diff --git a/src/Server/DeploymentFramework/BusinessLogic/BusinessLogic.csproj b/src/Server/DeploymentFramework/BusinessLogic/BusinessLogic.csproj index 60e8464..672ee6f 100644 --- a/src/Server/DeploymentFramework/BusinessLogic/BusinessLogic.csproj +++ b/src/Server/DeploymentFramework/BusinessLogic/BusinessLogic.csproj @@ -76,6 +76,7 @@ + diff --git a/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Contracts/IServersRepository.cs b/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Contracts/IServersRepository.cs index 6a980e3..4e51c06 100644 --- a/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Contracts/IServersRepository.cs +++ b/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Contracts/IServersRepository.cs @@ -20,5 +20,7 @@ public interface IServersRepository void AddServer(Server server); void UpdateParameters(ServerParameter parameter); + + void AddParameter(ServerParameter parameter); } } diff --git a/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Entities/ServerServerParameter.cs b/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Entities/ServerServerParameter.cs new file mode 100644 index 0000000..8aac9cd --- /dev/null +++ b/src/Server/DeploymentFramework/BusinessLogic/Domain/Deployment/Entities/ServerServerParameter.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Baud.Deployment.BusinessLogic.Domain.Deployment.Entities +{ + /// + /// A helper class used in Server Parameters editor. + /// + public class ServerServerParameter : EntityBase + { + public Server Server { get; set; } + public ServerParameter ServerParameter { get; set; } + } +} diff --git a/src/Server/DeploymentFramework/Database/Deployment/ServersRepository.cs b/src/Server/DeploymentFramework/Database/Deployment/ServersRepository.cs index e5a3a0b..afcdb1e 100644 --- a/src/Server/DeploymentFramework/Database/Deployment/ServersRepository.cs +++ b/src/Server/DeploymentFramework/Database/Deployment/ServersRepository.cs @@ -55,5 +55,10 @@ public void UpdateParameters(ServerParameter parameter) Context.AttachAsModified(parameter, x => x.Value); } + + public void AddParameter(ServerParameter parameter) + { + Context.ServerParameters.Add(parameter); + } } } diff --git a/src/Server/DeploymentFramework/Database/Security/PositionsRepository.cs b/src/Server/DeploymentFramework/Database/Security/PositionsRepository.cs index 98fc3a5..a1e46ff 100644 --- a/src/Server/DeploymentFramework/Database/Security/PositionsRepository.cs +++ b/src/Server/DeploymentFramework/Database/Security/PositionsRepository.cs @@ -1,6 +1,6 @@ using System; -using System.Data.Entity; using System.Collections.Generic; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/Server/DeploymentFramework/Database/Security/RolesRepository.cs b/src/Server/DeploymentFramework/Database/Security/RolesRepository.cs index 9f8457a..4c8ee18 100644 --- a/src/Server/DeploymentFramework/Database/Security/RolesRepository.cs +++ b/src/Server/DeploymentFramework/Database/Security/RolesRepository.cs @@ -1,6 +1,6 @@ using System; -using System.Data.Entity; using System.Collections.Generic; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs b/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs index e176aee..f72313a 100644 --- a/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs +++ b/src/Server/DeploymentFramework/Database/Security/UsersRepository.cs @@ -1,6 +1,6 @@ using System; -using System.Data.Entity; using System.Collections.Generic; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/Server/DeploymentFramework/Web/Areas/Deployment/Controllers/ServersController.cs b/src/Server/DeploymentFramework/Web/Areas/Deployment/Controllers/ServersController.cs index 853ef66..0b6cb1d 100644 --- a/src/Server/DeploymentFramework/Web/Areas/Deployment/Controllers/ServersController.cs +++ b/src/Server/DeploymentFramework/Web/Areas/Deployment/Controllers/ServersController.cs @@ -133,8 +133,8 @@ public virtual ActionResult EditParameters(int serverID, FormCollection form) // Three items (ID, Name, Value) for each Parameter passed, hence / 3. for (int i = 0; i < form.Count / 3; i++) { - var id = Int32.Parse(form.Get("Parameters[" + i + "].ID")); - var value = form.Get("Parameters[" + i + "].Value"); + var id = int.Parse(form.Get("Server.Parameters[" + i + "].ID")); + var value = form.Get("Server.Parameters[" + i + "].Value"); var parameter = uow.Servers.GetParameterByID(id); parameter.Value = value; @@ -144,7 +144,7 @@ public virtual ActionResult EditParameters(int serverID, FormCollection form) uow.Commit(); var server = uow.Servers.GetServerDetail(serverID); - return View(server); + return View(new ServerServerParameter { Server = server, ServerParameter = new ServerParameter() }); } } @@ -159,7 +159,37 @@ public virtual ActionResult EditParameters(int serverID) return HttpNotFound(); } - return View(server); + return View(new ServerServerParameter { Server = server, ServerParameter = new ServerParameter() }); + } + } + + [HttpPost] + [ValidateAntiForgeryToken] + public virtual ActionResult AddParameter(int serverID, FormCollection form) + { + using (var uow = _deploymentUow()) + { + var server = uow.Servers.GetServerDetail(serverID); + + if (server == null) + { + return HttpNotFound(); + } + + var parameter = new ServerParameter + { + Name = form.Get("ServerParameter.Name"), + Value = form.Get("ServerParameter.Value"), + ServerID = serverID, + Created = DateTime.Now, + CreatedBy = -2 + }; + + uow.Servers.AddParameter(parameter); + uow.Commit(); + + // TODO add confirmation toast message + return RedirectToAction(Actions.EditParameters(serverID)); } } } diff --git a/src/Server/DeploymentFramework/Web/Areas/Deployment/Views/Servers/EditParameters.cshtml b/src/Server/DeploymentFramework/Web/Areas/Deployment/Views/Servers/EditParameters.cshtml index 2e8fca3..f898433 100644 --- a/src/Server/DeploymentFramework/Web/Areas/Deployment/Views/Servers/EditParameters.cshtml +++ b/src/Server/DeploymentFramework/Web/Areas/Deployment/Views/Servers/EditParameters.cshtml @@ -1,24 +1,27 @@ -@model Baud.Deployment.BusinessLogic.Domain.Deployment.Entities.Server +@model Baud.Deployment.BusinessLogic.Domain.Deployment.Entities.ServerServerParameter @using Baud.Deployment.Resources @{ ViewBag.Title = StringResources.EditParameters; } -

@StringResources.EditParametersFor @Model.Name

+

@StringResources.EditParametersFor @Model.Server.Name

+ + + @using (var f = Html.BeginCustomForm()) { using (var s = f.BeginSection()) { - for (int i = 0; i < Model.Parameters.Count(); i++) + for (int i = 0; i < Model.Server.Parameters.Count(); i++) { - @Html.HiddenFor(m => Model.Parameters[i].ID) + @Html.HiddenFor(m => Model.Server.Parameters[i].ID)
- @s.FieldFor(m => Model.Parameters[i].Name).Readonly().HideRequiredHint() + @s.FieldFor(m => Model.Server.Parameters[i].Name).Readonly().HideRequiredHint()
- @s.FieldFor(m => Model.Parameters[i].Value) + @s.FieldFor(m => Model.Server.Parameters[i].Value)
} @@ -30,5 +33,27 @@ } } + + +@using (var f = Html.BeginCustomForm("AddParameter?serverID=" + Model.Server.ID)) +{ + using (var s = f.BeginSection()) + { +
+
+ @s.FieldFor(m => Model.ServerParameter.Name) +
+
+ @s.FieldFor(m => Model.ServerParameter.Value) +
+
+ + using (var n = f.BeginNavigation()) + { + @n.Submit(StringResources.Save) + } + } +} + @Html.GuardedActionLink(StringResources.BackToList, MVC.Deployment.Servers.Index(), new SimpleHtmlAttributes("class", "btn btn-default")) -@Html.GuardedActionLink(StringResources.BackToDetail, MVC.Deployment.Servers.Detail(Model.ID), new SimpleHtmlAttributes("class", "btn btn-default")) \ No newline at end of file +@Html.GuardedActionLink(StringResources.BackToDetail, MVC.Deployment.Servers.Detail(Model.Server.ID), new SimpleHtmlAttributes("class", "btn btn-default")) \ No newline at end of file diff --git a/src/Server/DeploymentFramework/Web/Deployment.ServersController.generated.cs b/src/Server/DeploymentFramework/Web/Deployment.ServersController.generated.cs index 885d6de..50db99b 100644 --- a/src/Server/DeploymentFramework/Web/Deployment.ServersController.generated.cs +++ b/src/Server/DeploymentFramework/Web/Deployment.ServersController.generated.cs @@ -79,6 +79,12 @@ public virtual System.Web.Mvc.ActionResult EditParameters() { return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.EditParameters); } + [NonAction] + [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode] + public virtual System.Web.Mvc.ActionResult AddParameter() + { + return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.AddParameter); + } [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode] public ServersController Actions { get { return MVC.Deployment.Servers; } } @@ -100,6 +106,7 @@ public class ActionNamesClass public readonly string Edit = "Edit"; public readonly string Add = "Add"; public readonly string EditParameters = "EditParameters"; + public readonly string AddParameter = "AddParameter"; } [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode] @@ -110,6 +117,7 @@ public class ActionNameConstants public const string Edit = "Edit"; public const string Add = "Add"; public const string EditParameters = "EditParameters"; + public const string AddParameter = "AddParameter"; } @@ -240,6 +248,19 @@ public override System.Web.Mvc.ActionResult EditParameters(int serverID) return callInfo; } + [NonAction] + partial void AddParameterOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, int serverID, System.Web.Mvc.FormCollection form); + + [NonAction] + public override System.Web.Mvc.ActionResult AddParameter(int serverID, System.Web.Mvc.FormCollection form) + { + var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.AddParameter); + ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "serverID", serverID); + ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "form", form); + AddParameterOverride(callInfo, serverID, form); + return callInfo; + } + } }