Skip to content

Commit

Permalink
Add Position and Roles through UI. Tweaked UpdateName and Enable/Disa…
Browse files Browse the repository at this point in the history
…ble methods.
  • Loading branch information
Berzeger committed Jul 17, 2015
1 parent 6f50d19 commit d5772f0
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IPositionsRepository

void Disable(short id);

void UpdateName(short id, string name);
void UpdateName(short id);

void AddPosition(Position position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IRolesRepository

void Disable(short id);

void UpdateName(short id, string name);
void UpdateName(short id);

void AddRole(Role role);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ public void Disable(short id)
x => x.IsActive);
}

public void UpdateName(short id, string name)
public void UpdateName(short id)
{
Position position = GetPositionDetail(id);
position.Name = name;

Context.AttachAsModified(position,
x => x.Name);
}

public void AddPosition(Position position)
{
Context.Positions.Add(position);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ public void Disable(short id)
x => x.IsActive);
}

public void UpdateName(short id, string name)
public void UpdateName(short id)
{
Role role = GetRoleDetail(id);
role.Name = name;

Context.AttachAsModified(role,
x => x.Name);
}

public void AddRole(Role role)
{
Context.Roles.Add(role);
}
}
}

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,12 @@
<data name="ActiveTo" xml:space="preserve">
<value>Aktivní do</value>
</data>
<data name="AddNewPosition" xml:space="preserve">
<value>Přidat novou pozici</value>
</data>
<data name="AddNewRole" xml:space="preserve">
<value>Přidat novou roli</value>
</data>
<data name="AddNewUser" xml:space="preserve">
<value>Přidat nového uživatele</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Server/DeploymentFramework/Resources/StringResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<data name="ActiveTo" xml:space="preserve">
<value>Active to</value>
</data>
<data name="AddNewPosition" xml:space="preserve">
<value>Add new position</value>
</data>
<data name="AddNewRole" xml:space="preserve">
<value>Add new role</value>
</data>
<data name="AddNewUser" xml:space="preserve">
<value>Add new user</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.Positions;
using Baud.Deployment.Web.Framework.Web;

Expand Down Expand Up @@ -60,11 +61,6 @@ public virtual ActionResult Disable(short id)
return HttpNotFound();
}

if (!TryUpdateModel(position))
{
return View(position);
}

uow.Positions.Disable(id);
uow.Commit();

Expand All @@ -84,11 +80,6 @@ public virtual ActionResult Enable(short id)
return HttpNotFound();
}

if (!TryUpdateModel(position))
{
return View(position);
}

uow.Positions.Enable(id);
uow.Commit();

Expand All @@ -115,7 +106,7 @@ public virtual ActionResult UpdateName(short id, string name)
return View(position);
}

uow.Positions.UpdateName(id, name);
uow.Positions.UpdateName(id);
uow.Commit();

// TODO add confirmation toast message
Expand All @@ -137,5 +128,35 @@ public virtual ActionResult UpdateName(short id)
return View(position);
}
}

public virtual ActionResult Add()
{
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Add(FormCollection form)
{
using (var uow = _securityUow())
{
var position = new Position();

// TODO Following two lines need fixing (we shouldn't have to type these properties in manually).
position.Created = DateTime.Now;
position.CreatedBy = -2;

if (!TryUpdateModel(position))
{
return View(position);
}

uow.Positions.AddPosition(position);
uow.Commit();

// TODO add confirmation toast message
return RedirectToAction(Actions.Index());
}
}
}
}
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.Roles;
using Baud.Deployment.Web.Framework.Security;
using Baud.Deployment.Web.Framework.Web;
Expand Down Expand Up @@ -61,11 +62,6 @@ public virtual ActionResult Disable(short id)
return HttpNotFound();
}

if (!TryUpdateModel(role))
{
return View(role);
}

uow.Roles.Disable(id);
uow.Commit();

Expand All @@ -85,11 +81,6 @@ public virtual ActionResult Enable(short id)
return HttpNotFound();
}

if (!TryUpdateModel(role))
{
return View(role);
}

uow.Roles.Enable(id);
uow.Commit();

Expand All @@ -116,7 +107,7 @@ public virtual ActionResult UpdateName(short id, string name)
return View(role);
}

uow.Roles.UpdateName(id, name);
uow.Roles.UpdateName(id);
uow.Commit();

// TODO add confirmation toast message
Expand All @@ -138,5 +129,35 @@ public virtual ActionResult UpdateName(short id)
return View(role);
}
}

public virtual ActionResult Add()
{
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Add(FormCollection form)
{
using (var uow = _securityUow())
{
var role = new Role();

// TODO Following two lines need fixing (we shouldn't have to type these properties in manually).
role.Created = DateTime.Now;
role.CreatedBy = -2;

if (!TryUpdateModel(role))
{
return View(role);
}

uow.Roles.AddRole(role);
uow.Commit();

// TODO add confirmation toast message
return RedirectToAction(Actions.Index());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@model Baud.Deployment.BusinessLogic.Domain.Security.Entities.Position
@using Baud.Deployment.Resources

@{
ViewBag.Title = StringResources.AddNewPosition;
}

<h2>@ViewBag.Title</h2>

@using (var f = Html.BeginCustomForm())
{
using (var s = f.BeginSection())
{
@s.FieldFor(m => m.Name)
@s.FieldFor(m => m.IsActive).AsDropDown().WithTrueAs(StringResources.Yes).WithFalseAs(StringResources.No)
}

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.AddNewPosition, MVC.Security.Positions.Add())

@if (Model.Any())
{
<table class="table table-striped">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@model Baud.Deployment.BusinessLogic.Domain.Security.Entities.Role
@using Baud.Deployment.Resources

@{
ViewBag.Title = StringResources.AddNewRole;
}

<h2>@ViewBag.Title</h2>

@using (var f = Html.BeginCustomForm())
{
using (var s = f.BeginSection())
{
@s.FieldFor(m => m.Name)
@s.FieldFor(m => m.IsActive).AsDropDown().WithTrueAs(StringResources.Yes).WithFalseAs(StringResources.No)
}

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.AddNewRole, MVC.Security.Roles.Add())

@if (Model.Any())
{
<table class="table table-striped">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class ActionNamesClass
public readonly string Disable = "Disable";
public readonly string Enable = "Enable";
public readonly string UpdateName = "UpdateName";
public readonly string Add = "Add";
}

[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
Expand All @@ -116,6 +117,7 @@ public class ActionNameConstants
public const string Disable = "Disable";
public const string Enable = "Enable";
public const string UpdateName = "UpdateName";
public const string Add = "Add";
}


Expand All @@ -129,9 +131,11 @@ public class ViewsClass
public _ViewNamesClass ViewNames { get { return s_ViewNames; } }
public class _ViewNamesClass
{
public readonly string Add = "Add";
public readonly string Index = "Index";
public readonly string UpdateName = "UpdateName";
}
public readonly string Add = "~/Areas/Security/Views/Positions/Add.cshtml";
public readonly string Index = "~/Areas/Security/Views/Positions/Index.cshtml";
public readonly string UpdateName = "~/Areas/Security/Views/Positions/UpdateName.cshtml";
}
Expand Down Expand Up @@ -216,6 +220,29 @@ public override System.Web.Mvc.ActionResult UpdateName(short id)
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
Loading

0 comments on commit d5772f0

Please sign in to comment.