Skip to content

Commit

Permalink
Users add. Relates to Baud-UCS#26 and Baud-UCS#27.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berzeger committed Jul 16, 2015
1 parent 4342a5c commit 6f50d19
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface IUsersRepository
User GetUserDetail(short id);

void UpdateUser(short id, User user);

void AddUser(User user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="ActiveTo" xml:space="preserve">
<value>Aktivní do</value>
</data>
<data name="AddNewUser" xml:space="preserve">
<value>Přidat nového uživatele</value>
</data>
<data name="BackToList" xml:space="preserve">
<value>Zpět na seznam</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Server/DeploymentFramework/Resources/StringResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="ActiveTo" xml:space="preserve">
<value>Active to</value>
</data>
<data name="AddNewUser" xml:space="preserve">
<value>Add new user</value>
</data>
<data name="BackToList" xml:space="preserve">
<value>Back to list</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,7 @@ public UsersController(Func<ISecurityUow> 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;

Expand Down Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@model Baud.Deployment.BusinessLogic.Domain.Security.Entities.User
@using Baud.Deployment.Resources

@{
ViewBag.Title = StringResources.AddNewUser;
}

<h2>@ViewBag.Title</h2>

@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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
}
</div>

@Html.GuardedActionLink(StringResources.AddNewUser, MVC.Security.Users.Add())

@if (Model.Any())
{
<table class="table table-striped">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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";
}


Expand All @@ -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";
Expand Down Expand Up @@ -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;
}

}
}

Expand Down
1 change: 1 addition & 0 deletions src/Server/DeploymentFramework/Web/Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<Content Include="Areas\Security\Views\Roles\Index.cshtml" />
<Content Include="Areas\Security\Views\Positions\Index.cshtml" />
<Content Include="Areas\Security\Views\Positions\UpdateName.cshtml" />
<Content Include="Areas\Security\Views\Users\Add.cshtml" />
<None Include="T4MVC.tt.settings.xml" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
Expand Down

0 comments on commit 6f50d19

Please sign in to comment.