Skip to content

Commit

Permalink
Merge pull request #42 from Berzeger/develop
Browse files Browse the repository at this point in the history
Server Parameters add. Closes #28 and #29.
  • Loading branch information
gius committed Jul 20, 2015
2 parents b553a51 + 8f29f76 commit 92fc7c2
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="Domain\Deployment\Entities\Project.cs" />
<Compile Include="Domain\Deployment\Entities\Server.cs" />
<Compile Include="Domain\Deployment\Entities\ServerParameter.cs" />
<Compile Include="Domain\Deployment\Entities\ServerServerParameter.cs" />
<Compile Include="Domain\Deployment\Entities\ServerSite.cs" />
<Compile Include="Domain\Deployment\Enums\InstallationState.cs" />
<Compile Include="Domain\Deployment\Enums\LogSeverity.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface IServersRepository
void AddServer(Server server);

void UpdateParameters(ServerParameter parameter);

void AddParameter(ServerParameter parameter);
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A helper class used in Server Parameters editor.
/// </summary>
public class ServerServerParameter : EntityBase
{
public Server Server { get; set; }
public ServerParameter ServerParameter { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public void UpdateParameters(ServerParameter parameter)
Context.AttachAsModified(parameter,
x => x.Value);
}

public void AddParameter(ServerParameter parameter)
{
Context.ServerParameters.Add(parameter);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() });
}
}

Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

<h2>@StringResources.EditParametersFor @Model.Name</h2>
<h2>@StringResources.EditParametersFor @Model.Server.Name</h2>

<!-- Edit Parameters -->

@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)
<div class="row">
<div class="col-md-6">
@s.FieldFor(m => Model.Parameters[i].Name).Readonly().HideRequiredHint()
@s.FieldFor(m => Model.Server.Parameters[i].Name).Readonly().HideRequiredHint()
</div>
<div class="col-md-6">
@s.FieldFor(m => Model.Parameters[i].Value)
@s.FieldFor(m => Model.Server.Parameters[i].Value)
</div>
</div>
}
Expand All @@ -30,5 +33,27 @@
}
}

<!-- Add new Parameter -->

@using (var f = Html.BeginCustomForm("AddParameter?serverID=" + Model.Server.ID))
{
using (var s = f.BeginSection())
{
<div class="row">
<div class="col-md-6">
@s.FieldFor(m => Model.ServerParameter.Name)
</div>
<div class="col-md-6">
@s.FieldFor(m => Model.ServerParameter.Value)
</div>
</div>

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"))
@Html.GuardedActionLink(StringResources.BackToDetail, MVC.Deployment.Servers.Detail(Model.Server.ID), new SimpleHtmlAttributes("class", "btn btn-default"))
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand All @@ -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]
Expand All @@ -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";
}


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

}
}

Expand Down

0 comments on commit 92fc7c2

Please sign in to comment.