Skip to content

Commit

Permalink
added initial models controller prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkis117 committed Jan 25, 2017
1 parent 3bc996c commit edfee7e
Show file tree
Hide file tree
Showing 25 changed files with 625 additions and 468 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003156"
"version": "1.0.0-preview2-1-003177"
}
}
16 changes: 16 additions & 0 deletions src/GenericMvc.Test.App/Controllers/ModelsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using GenericMvc.Controllers;

// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace GenericMvc.Test.App.Controllers
{
public class ModelsController : BasicModelsController
{

}
}
3 changes: 3 additions & 0 deletions src/GenericMvc.Test.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using GenericMvc.Test.App.Models;
using Microsoft.EntityFrameworkCore;
using GenericMvc.StartupUtils;
using GenericMvc.Controllers;

namespace GenericMvc.Test.App
{
Expand Down Expand Up @@ -56,6 +57,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF

context.SaveChanges();

BasicModelsController.Initialize(typeof(Person));

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
2 changes: 1 addition & 1 deletion src/GenericMvc.Test.App/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
<li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li>
<li><a asp-area="" asp-controller="Person" asp-action="Index">People</a></li>
<li><a asp-area="" asp-controller="Models" asp-action="Index">Models</a></li>
</ul>
</div>
</div>
Expand Down
244 changes: 122 additions & 122 deletions src/GenericMvc.Test.App/project.lock.json

Large diffs are not rendered by default.

208 changes: 104 additions & 104 deletions src/GenericMvc.Test.Library/project.lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/GenericMvc/Attributes/ModelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;

namespace GenericMvcUtilities.Attributes
namespace GenericMvc.Attributes
{
public class ModelInfo : Attribute
{
Expand Down
2 changes: 1 addition & 1 deletion src/GenericMvc/Clients/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RouteInfo(string controllerName = "auth", string login = "login", string
/// <summary>
/// User Xamarin connectivity package to test connection status on creation
/// </summary>
/// <seealso cref="GenericMvc.Client.IAuthClient" />
/// <seealso cref="GenericMvcModels.Client.IAuthClient" />
/// <seealso cref="System.IDisposable" />
public class AuthClient : IAuthClient, IDisposable
{
Expand Down
2 changes: 1 addition & 1 deletion src/GenericMvc/Controllers/AuthApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IAuthApiController
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <seealso cref="Microsoft.AspNetCore.Mvc.Controller" />
/// <seealso cref="GenericMvc.Controllers.IAuthApiController" />
/// <seealso cref="GenericMvcModels.Controllers.IAuthApiController" />
[Authorize]
[Route("/api/[controller]/[action]/")]
public class AuthApiController<TKey, TUser> : Controller, IAuthApiController
Expand Down
2 changes: 0 additions & 2 deletions src/GenericMvc/Controllers/BasicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public BasicController(IEntityRepository<T> repository, ILogger<T> logger, strin
{
IsMutable = true;



try
{
if (repository == null)
Expand Down
12 changes: 12 additions & 0 deletions src/GenericMvc/Controllers/BasicMvc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GenericMvc
{
public static class BasicMvc
{
public static string Layout { get; set; } = null;
}
}
7 changes: 6 additions & 1 deletion src/GenericMvc/Controllers/IBaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

namespace GenericMvc.Controllers
{
public interface IReadOnlyBasicController<TKey, T>
public interface IBaseController
{

}

public interface IReadOnlyBasicController<TKey, T> : IBaseController
where T : class
where TKey : IEquatable<TKey>
{
Expand Down
62 changes: 56 additions & 6 deletions src/GenericMvc/Controllers/ModelsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace GenericMvcUtilities.Controllers
namespace GenericMvc.Controllers
{
public class BasicModelsController : Controller
{
//protected static List<>
private static Type _appAssembly;

public static void Register(Controller controller)
private static Assembly _currentAssembly;

public static Assembly CurrentAssembly { get { return _currentAssembly; } }

public static void Initialize(Type typeInCurrentAssembly)
{
if (typeInCurrentAssembly == null)
throw new ArgumentNullException(nameof(typeInCurrentAssembly));

_appAssembly = typeInCurrentAssembly;

_currentAssembly = typeInCurrentAssembly.GetTypeInfo().Assembly;

var types = CurrentAssembly.GetTypes();

var controls = types.Where(x => x.GetTypeInfo().GetInterfaces()
.Any(y => y == typeof(IBaseController)) && !x.GetTypeInfo().IsAbstract);

foreach (var item in controls)
{
Register(item);
}
}

public class ViewModel
{
public string Name { get; set; }

public Type Controller { get; set; }
}

protected static List<ViewModel> viewModels = new List<ViewModel>();

public static void Register(Type controller)
{
if (controller == null)
throw new ArgumentNullException(nameof(controller));

var controllerName = controller.RouteData.Values["controller"].ToString();
var controllerName = "Controller";

string name = controller.Name;

if (controllerName.EndsWith(controllerName, StringComparison.OrdinalIgnoreCase))
{
name = name.Substring(0, name.Length - controllerName.Length);
}

var viewModel = new ViewModel
{
Name = name,
Controller = controller
};

viewModels.Add(viewModel);
}

public BasicModelsController()
[Route("[controller]/[action]/"), HttpGet]
public IActionResult Index()
{

return View("~/Views/Shared/BasicMvc/Models.cshtml", viewModels);
}
}
}
1 change: 1 addition & 0 deletions src/GenericMvc/Controllers/ReadOnlyBasicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace GenericMvc.Controllers
Expand Down
2 changes: 1 addition & 1 deletion src/GenericMvc/Repositories/PairedRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace GenericMvc.Repositories
///
/// MimeTypes should be included in non get with data calls
/// </summary>
/// <seealso cref="GenericMvc.Repositories.IRepository{TViewModel}" />
/// <seealso cref="GenericMvcModels.Repositories.IRepository{TViewModel}" />
public abstract class PairedRepository<TKey, TViewModel, TEntity, TEntityRepo, TFileRepo> : IRepository<TViewModel>
where TKey : IEquatable<TKey>
where TViewModel : class, IModelFile<TKey>, new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface IPendingUserView
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TPendingUser">The type of the user.</typeparam>
/// <seealso cref="GenericMvc.ViewModels.UserManager.IPendingUserView" />
/// <seealso cref="GenericMvcModels.ViewModels.UserManager.IPendingUserView" />
public class PendingUserDetails<TKey, TPendingUser> : IPendingUserView
where TKey : IEquatable<TKey>
where TPendingUser : PendingUser<TKey>, Models.IPrivilegedUserConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IUserView
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <typeparam name="TRole">The type of the role.</typeparam>
/// <seealso cref="GenericMvc.ViewModels.UserManager.IUserView" />
/// <seealso cref="GenericMvcModels.ViewModels.UserManager.IUserView" />
public class UserDetailsViewModel<TKey, TUser, TRole> : IUserView
where TKey : IEquatable<TKey>
where TUser : IdentityUser<TKey>, Models.IPrivilegedUserConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PendingUserViewModel(TPendingUser pendingUser)
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <seealso cref="GenericMvc.ViewModels.UserManager.IUserIndexView" />
/// <seealso cref="GenericMvcModels.ViewModels.UserManager.IUserIndexView" />
public class UserIndexViewModel<TKey, TUser> : IUserIndexView
where TKey : IEquatable<TKey>
where TUser : IdentityUser<TKey>, Models.IPrivilegedUserConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@{
var typeName = Model.Data.GetType().Name;
ViewData["Title"] = Model.ControllerName + " " + Model.Action;

Layout = BasicMvc.Layout ?? Layout;
}

<section class="well">
Expand Down
2 changes: 2 additions & 0 deletions src/GenericMvc/Views/Shared/BasicMvc/DeleteContainer.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

@{
ViewData["Title"] = Model.ControllerName +" "+ Model.Action;

Layout = BasicMvc.Layout ?? Layout;
}

<section class="well">
Expand Down
2 changes: 2 additions & 0 deletions src/GenericMvc/Views/Shared/BasicMvc/DetailsContainer.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

@{
ViewData["Title"] = Model.ControllerName + " " + Model.Action;

Layout = BasicMvc.Layout ?? Layout;
}

<section class="well">
Expand Down
6 changes: 4 additions & 2 deletions src/GenericMvc/Views/Shared/BasicMvc/IndexContainer.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@using GenericMvc.ViewModels.Basic;
@model GenericMvc.ViewModels.Basic.IndexViewModel
@using GenericMvc.ViewModels.Basic
@model GenericMvc.ViewModels.Basic.IndexViewModel

@{
ViewData["Title"] = Model.ControllerName + " " + Model.Action;

Layout = BasicMvc.Layout ?? Layout;
}

<section class="well">
Expand Down
64 changes: 64 additions & 0 deletions src/GenericMvc/Views/Shared/BasicMvc/Models.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@using GenericMvc.Controllers
@model List<BasicModelsController.ViewModel>

@{
ViewData["Title"] = "Models - Index";

Layout = BasicMvc.Layout ?? Layout;
}

<section class="well">
<header class="row">
<div class="col-md-6">
<div class="pull-left">
<h2 class="text-primary">Models</h2>
<h4>All registered models in the Application</h4>
</div>
</div>
<div class="col-md-6">
<div class="pull-right">
<h2 class="text-primary"><i class="material-icons">list</i> Index</h2>
<h4>@Model.Count Models</h4>
</div>
</div>
</header>
<hr class="shadow-z-1 primarycolor" />
<div class="row">
<div class="col-md-3">
<div class="pull-left">
</div>
</div>
<div class="col-md-9">
<div class="pull-right">
</div>
</div>
</div>
<table class="table table-striped table-responsive table-hover">
<tr>
<th>Name</th>
<th>Actions</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td>
<a asp-controller="@item.Name" asp-action="Index">Index</a>
</td>
</tr>
}
</table>
<hr class="shadow-z-1 primarycolor" />
<footer class="row">
<div class="col-md-6">
<div class="pull-left">
<h5 class="text-primary">Models</h5>
</div>
</div>
<div class="col-md-6">
<div class="pull-right">
<h5><i class="material-icons">list</i> Index</h5>
</div>
</div>
</footer>
</section>
Loading

0 comments on commit edfee7e

Please sign in to comment.