Skip to content

Commit

Permalink
Added edit bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmoore committed Jun 6, 2014
1 parent 664b60a commit 429b96f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public ActionResult Create(Guid websiteId)
[HttpPost]
public ActionResult Create(CreateBindingViewModel vm)
{
if (!ModelState.IsValid)
return View(vm);

var binding = new Binding
{
HostName = vm.HostName,
Expand All @@ -39,7 +42,36 @@ public ActionResult Create(CreateBindingViewModel vm)
};
_webSiteRepository.AddBindingToWebSite(vm.WebsiteId, binding);

return RedirectToAction("Detail", "WebSite", new {Id = vm.WebsiteId});
return RedirectToAction("Detail", "WebSite", new { area = ControlPanelAreaRegistration.Name, Id = vm.WebsiteId });
}

public ActionResult Edit(Guid id)
{
var binding = _webSiteRepository.RetrieveBinding(id);
if (binding == null)
return HttpNotFound();

return View(new EditBindingViewModel(binding));
}

[HttpPost]
public ActionResult Edit(EditBindingViewModel vm)
{
var binding = _webSiteRepository.RetrieveBinding(vm.Id);
if (binding == null)
return HttpNotFound();

if (!ModelState.IsValid)
return View(vm);

binding.HostName = vm.HostName;
binding.Port = vm.Port;
binding.Protocol = vm.Protocol.ToString().ToLower();
binding.IpAddress = vm.IpAddress;
binding.CertificateThumbprint = vm.CertificateThumbprint;
_webSiteRepository.UpdateBinding(binding);

return RedirectToAction("Detail", "WebSite", new { area = ControlPanelAreaRegistration.Name, Id = binding.WebSiteId });
}

[HttpPost]
Expand All @@ -50,14 +82,41 @@ public ActionResult Delete(Guid id)
return HttpNotFound();

_webSiteRepository.RemoveBinding(id);
return RedirectToAction("Detail", "WebSite", new {Id = binding.WebSiteId});
return RedirectToAction("Detail", "WebSite", new { area = ControlPanelAreaRegistration.Name, Id = binding.WebSiteId });
}
}

public class CreateBindingViewModel
public class CreateBindingViewModel : BindingViewModel
{
public CreateBindingViewModel()
{
Port = 80;
IpAddress = "*";
}

public Guid WebsiteId { get; set; }
}

public class EditBindingViewModel : BindingViewModel
{
public EditBindingViewModel() {}

public EditBindingViewModel(Binding binding)
{
HostName = binding.HostName;
Port = binding.Port;
Protocol = (Protocol) Enum.Parse(typeof (Protocol), binding.Protocol, true);
IpAddress = binding.IpAddress;
CertificateThumbprint = binding.CertificateThumbprint;
}

public Guid Id { get; set; }
}

public class BindingViewModel
{
private static readonly List<Certificate> CertificatesCache = new List<Certificate>();
static CreateBindingViewModel()
static BindingViewModel()
{
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
Expand All @@ -72,12 +131,6 @@ static CreateBindingViewModel()
store.Close();
}

public CreateBindingViewModel()
{
Port = 80;
IpAddress = "*";
}

[Required]
public string HostName { get; set; }
[Required]
Expand All @@ -89,7 +142,6 @@ public CreateBindingViewModel()
public string IpAddress { get; set; }
[ExistsIn("Certificates", "Thumbprint", "Name")]
public string CertificateThumbprint { get; set; }
public Guid WebsiteId { get; set; }

public IList<Certificate> Certificates { get { return CertificatesCache; } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using ChameleonForms.Templates.TwitterBootstrap3
@model CreateBindingViewModel

<h1>Create Website</h1>
<h1>Create Binding</h1>

@using (var f = Html.BeginChameleonForm())
{
Expand All @@ -19,6 +19,6 @@

using (var n = f.BeginNavigation())
{
@n.Submit("Create").WithStyle(EmphasisStyle.Primary).WithIcon("globe")
@n.Submit("Create").WithStyle(EmphasisStyle.Primary).WithIcon("cloud-upload")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@using AzureWebFarm.ControlPanel.Areas.ControlPanel.Controllers
@using ChameleonForms.Templates.TwitterBootstrap3
@model EditBindingViewModel

<h1>Create Binding</h1>

@using (var f = Html.BeginChameleonForm())
{
using (var s = f.BeginSection())
{
@s.FieldFor(m => m.HostName)
@s.FieldFor(m => m.IpAddress)
@s.FieldFor(m => m.Port)
@s.FieldFor(m => m.Protocol)
@s.FieldFor(m => m.CertificateThumbprint)
}

using (var n = f.BeginNavigation())
{
@n.Submit("Edit").WithStyle(EmphasisStyle.Primary).WithIcon("cloud-upload")
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
@using AzureWebFarm.ControlPanel.Areas.ControlPanel.Views
@using AzureWebFarm.Entities
@using MvcContrib.UI.Grid
@using AzureWebFarm.ControlPanel.Areas.ControlPanel.Controllers
@model WebSiteDetailViewModel

@helper BindingButtons(Binding b)
{
<a class="btn btn-primary" href="@Url.Action("Edit", "Binding", new {b.Id})"><span class="glyphicon glyphicon-cloud-upload"></span> Edit binding</a>
<form method="post" action="@Url.Action("Delete", "Binding", new {b.Id})" style="display: inline;"><button class="btn btn-danger" type="submit" onclick="return confirm('Are you sure you want to delete the binding for @b.Protocol://@b.HostName:@b.Port');"><span class="glyphicon glyphicon-remove"></span> Delete</button></form>
}

<h1>Website: @Model.Site.Name</h1>

<div class="panel panel-primary">
Expand All @@ -16,7 +23,7 @@
c.For(b => b.Port);
c.For(b => b.IpAddress);
c.For(b => new HtmlString(!string.IsNullOrEmpty(b.CertificateThumbprint) ? HttpUtility.HtmlEncode(b.CertificateThumbprint) : "<em>None</em>")).Named("Certificate Thumbprint");
c.For(b => new HtmlString(string.Format("<form method=\"post\" action=\"{0}\"><button class=\"btn btn-danger\" type=\"submit\" onclick=\"return confirm('Are you sure you want to delete the binding for {1}://{2}:{3}');\"><span class=\"glyphicon glyphicon-remove\"></span> Delete</button></form>", Url.Action("Delete", "Binding", new {b.Id}), b.Protocol, b.HostName, b.Port))).Named("Delete Binding");
c.For(b => BindingButtons(b)).Named("Actions");
})
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions AzureWebFarm.ControlPanel/AzureWebFarm.ControlPanel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
<ItemGroup>
<EmbeddedResource Include="Areas\ControlPanel\Views\Binding\Create.cshtml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Areas\ControlPanel\Views\Binding\Edit.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down

4 comments on commit 429b96f

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 103 is now running

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 1.0.0-beta.1+68 outcome was FAILURE
Summary: Tests passed: 67; exit code 1 (new) Build time: 0:0:0

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 104 is now running

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 1.0.0-PullRequest.17+69 outcome was FAILURE
Summary: Tests failed: 1 (1 new), passed: 66 Build time: 0:0:0

Failed tests

AzureWebFarm.Tests.dll: AzureWebFarm.Tests.Services.BackgroundWorkerServiceShould.Run_executable: Test(s) failed.   C:\TeamCity\buildAgent\work\73be575006f9fc3e\AzureWebFarm.Tests\bin\Release\Executables\SiteName\TestApp1\file.txt didn't exist
  Expected: True
  But was:  False

Please sign in to comment.