From 6f50d1985680e820acb30f1d975b1083a2e579e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Vondr=C3=A1=C5=A1ek?= Date: Thu, 16 Jul 2015 17:18:37 +0200 Subject: [PATCH] Users add. Relates to #26 and #27. --- .../Security/Contracts/IUsersRepository.cs | 2 ++ .../Database/Security/UsersRepository.cs | 5 +++ .../Resources/StringResources.Designer.cs | 9 +++++ .../Resources/StringResources.cs-CZ.resx | 3 ++ .../Resources/StringResources.resx | 3 ++ .../Security/Controllers/UsersController.cs | 33 ++++++++++++++++++- .../Web/Areas/Security/Views/Users/Add.cshtml | 27 +++++++++++++++ .../Areas/Security/Views/Users/Index.cshtml | 2 ++ .../Security.PositionsController.generated.cs | 2 -- .../Web/Security.RolesController.generated.cs | 2 -- .../Web/Security.UsersController.generated.cs | 27 +++++++++++++++ src/Server/DeploymentFramework/Web/Web.csproj | 1 + 12 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Add.cshtml diff --git a/src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Contracts/IUsersRepository.cs b/src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Contracts/IUsersRepository.cs index a444f31..fdcec30 100644 --- a/src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Contracts/IUsersRepository.cs +++ b/src/Server/DeploymentFramework/BusinessLogic/Domain/Security/Contracts/IUsersRepository.cs @@ -14,5 +14,7 @@ public interface IUsersRepository User GetUserDetail(short id); void UpdateUser(short id, User user); + + void AddUser(User user); } } \ No newline at end of file diff --git a/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs b/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs index 5be3de0..571ef0e 100644 --- a/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs +++ b/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs @@ -38,5 +38,10 @@ public void UpdateUser(short id, User user) x => x.ActiveFrom, x => x.ActiveTo); } + + public void AddUser(User user) + { + Context.Users.Add(user); + } } } \ No newline at end of file diff --git a/src/Server/DeploymentFramework/Resources/StringResources.Designer.cs b/src/Server/DeploymentFramework/Resources/StringResources.Designer.cs index 059d0a6..48ddf8b 100644 --- a/src/Server/DeploymentFramework/Resources/StringResources.Designer.cs +++ b/src/Server/DeploymentFramework/Resources/StringResources.Designer.cs @@ -78,6 +78,15 @@ public static string ActiveTo { } } + /// + /// Looks up a localized string similar to Add new user. + /// + public static string AddNewUser { + get { + return ResourceManager.GetString("AddNewUser", resourceCulture); + } + } + /// /// Looks up a localized string similar to Back to list. /// diff --git a/src/Server/DeploymentFramework/Resources/StringResources.cs-CZ.resx b/src/Server/DeploymentFramework/Resources/StringResources.cs-CZ.resx index dabcbb9..fa49560 100644 --- a/src/Server/DeploymentFramework/Resources/StringResources.cs-CZ.resx +++ b/src/Server/DeploymentFramework/Resources/StringResources.cs-CZ.resx @@ -123,6 +123,9 @@ Aktivní do + + Přidat nového uživatele + Zpět na seznam diff --git a/src/Server/DeploymentFramework/Resources/StringResources.resx b/src/Server/DeploymentFramework/Resources/StringResources.resx index a0e7ffd..70d4dde 100644 --- a/src/Server/DeploymentFramework/Resources/StringResources.resx +++ b/src/Server/DeploymentFramework/Resources/StringResources.resx @@ -123,6 +123,9 @@ Active to + + Add new user + Back to list diff --git a/src/Server/DeploymentFramework/Web/Areas/Security/Controllers/UsersController.cs b/src/Server/DeploymentFramework/Web/Areas/Security/Controllers/UsersController.cs index 52ba7ac..a9187e5 100644 --- a/src/Server/DeploymentFramework/Web/Areas/Security/Controllers/UsersController.cs +++ b/src/Server/DeploymentFramework/Web/Areas/Security/Controllers/UsersController.cs @@ -4,6 +4,7 @@ using System.Web; using System.Web.Mvc; using Baud.Deployment.BusinessLogic.Domain.Security.Contracts; +using Baud.Deployment.BusinessLogic.Domain.Security.Entities; using Baud.Deployment.Web.Areas.Security.Models.Users; using Baud.Deployment.Web.Framework.Security; using Baud.Deployment.Web.Framework.Web; @@ -22,7 +23,7 @@ public UsersController(Func securityUow) ////[RequirePermission(Permissions.Security.UserRead)] public virtual ActionResult Index(IndexFilter filter, PagingData paging) { - paging.PageSize = 2; // only for testing + paging.PageSize = 10; // only for testing ViewBag.Filter = filter; @@ -91,5 +92,35 @@ public virtual ActionResult Edit(short id, FormCollection form) return RedirectToAction(Actions.Detail(id)); } } + + public virtual ActionResult Add() + { + return View(); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public virtual ActionResult Add(FormCollection form) + { + using (var uow = _securityUow()) + { + var user = new User(); + + // TODO Following two lines need fixing (we shouldn't have to type these properties in manually). + user.Created = DateTime.Now; + user.CreatedBy = -2; + + if (!TryUpdateModel(user)) + { + return View(user); + } + + uow.Users.AddUser(user); + uow.Commit(); + + // TODO add confirmation toast message + return RedirectToAction(Actions.Detail(user.ID)); + } + } } } \ No newline at end of file diff --git a/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Add.cshtml b/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Add.cshtml new file mode 100644 index 0000000..d6a58c2 --- /dev/null +++ b/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Add.cshtml @@ -0,0 +1,27 @@ +@model Baud.Deployment.BusinessLogic.Domain.Security.Entities.User +@using Baud.Deployment.Resources + +@{ + ViewBag.Title = StringResources.AddNewUser; +} + +

@ViewBag.Title

+ +@using (var f = Html.BeginCustomForm()) +{ + using (var s = f.BeginSection()) + { + @s.FieldFor(m => m.Login) + @s.FieldFor(m => m.FirstName) + @s.FieldFor(m => m.LastName) + @s.FieldFor(m => m.Email) + @s.FieldFor(m => m.ActiveFrom) + @s.FieldFor(m => m.ActiveTo) + @s.FieldFor(m => m.Note) + } + + using (var n = f.BeginNavigation()) + { + @n.Submit(StringResources.Save) + } +} diff --git a/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Index.cshtml b/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Index.cshtml index 775e07d..b74ae05 100644 --- a/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Index.cshtml +++ b/src/Server/DeploymentFramework/Web/Areas/Security/Views/Users/Index.cshtml @@ -24,6 +24,8 @@ } +@Html.GuardedActionLink(StringResources.AddNewUser, MVC.Security.Users.Add()) + @if (Model.Any()) { diff --git a/src/Server/DeploymentFramework/Web/Security.PositionsController.generated.cs b/src/Server/DeploymentFramework/Web/Security.PositionsController.generated.cs index 4a28179..355375c 100644 --- a/src/Server/DeploymentFramework/Web/Security.PositionsController.generated.cs +++ b/src/Server/DeploymentFramework/Web/Security.PositionsController.generated.cs @@ -129,11 +129,9 @@ public class ViewsClass public _ViewNamesClass ViewNames { get { return s_ViewNames; } } public class _ViewNamesClass { - public readonly string Detail = "Detail"; public readonly string Index = "Index"; public readonly string UpdateName = "UpdateName"; } - public readonly string Detail = "~/Areas/Security/Views/Positions/Detail.cshtml"; public readonly string Index = "~/Areas/Security/Views/Positions/Index.cshtml"; public readonly string UpdateName = "~/Areas/Security/Views/Positions/UpdateName.cshtml"; } diff --git a/src/Server/DeploymentFramework/Web/Security.RolesController.generated.cs b/src/Server/DeploymentFramework/Web/Security.RolesController.generated.cs index e94bea6..1aa19ee 100644 --- a/src/Server/DeploymentFramework/Web/Security.RolesController.generated.cs +++ b/src/Server/DeploymentFramework/Web/Security.RolesController.generated.cs @@ -129,11 +129,9 @@ public class ViewsClass public _ViewNamesClass ViewNames { get { return s_ViewNames; } } public class _ViewNamesClass { - public readonly string Detail = "Detail"; public readonly string Index = "Index"; public readonly string UpdateName = "UpdateName"; } - public readonly string Detail = "~/Areas/Security/Views/Roles/Detail.cshtml"; public readonly string Index = "~/Areas/Security/Views/Roles/Index.cshtml"; public readonly string UpdateName = "~/Areas/Security/Views/Roles/UpdateName.cshtml"; } diff --git a/src/Server/DeploymentFramework/Web/Security.UsersController.generated.cs b/src/Server/DeploymentFramework/Web/Security.UsersController.generated.cs index 90dfc1b..540e2f8 100644 --- a/src/Server/DeploymentFramework/Web/Security.UsersController.generated.cs +++ b/src/Server/DeploymentFramework/Web/Security.UsersController.generated.cs @@ -92,6 +92,7 @@ public class ActionNamesClass public readonly string Index = "Index"; public readonly string Detail = "Detail"; public readonly string Edit = "Edit"; + public readonly string Add = "Add"; } [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode] @@ -100,6 +101,7 @@ public class ActionNameConstants public const string Index = "Index"; public const string Detail = "Detail"; public const string Edit = "Edit"; + public const string Add = "Add"; } @@ -113,10 +115,12 @@ public class ViewsClass public _ViewNamesClass ViewNames { get { return s_ViewNames; } } public class _ViewNamesClass { + public readonly string Add = "Add"; public readonly string Detail = "Detail"; public readonly string Edit = "Edit"; public readonly string Index = "Index"; } + public readonly string Add = "~/Areas/Security/Views/Users/Add.cshtml"; public readonly string Detail = "~/Areas/Security/Views/Users/Detail.cshtml"; public readonly string Edit = "~/Areas/Security/Views/Users/Edit.cshtml"; public readonly string Index = "~/Areas/Security/Views/Users/Index.cshtml"; @@ -178,6 +182,29 @@ public override System.Web.Mvc.ActionResult Edit(short id, System.Web.Mvc.FormCo return callInfo; } + [NonAction] + partial void AddOverride(T4MVC_System_Web_Mvc_ActionResult callInfo); + + [NonAction] + public override System.Web.Mvc.ActionResult Add() + { + var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Add); + AddOverride(callInfo); + return callInfo; + } + + [NonAction] + partial void AddOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.Mvc.FormCollection form); + + [NonAction] + public override System.Web.Mvc.ActionResult Add(System.Web.Mvc.FormCollection form) + { + var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Add); + ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "form", form); + AddOverride(callInfo, form); + return callInfo; + } + } } diff --git a/src/Server/DeploymentFramework/Web/Web.csproj b/src/Server/DeploymentFramework/Web/Web.csproj index 0dadc2c..7d6cc50 100644 --- a/src/Server/DeploymentFramework/Web/Web.csproj +++ b/src/Server/DeploymentFramework/Web/Web.csproj @@ -429,6 +429,7 @@ +