public ActionResult Create(WebSiteCreateModel model)
        {
            try
            {
                if (!this.ValidateDuplicatedSites(model.Name))
                {
                    model.Certificates = this.GetCertificatesList();
                    return View(model);
                }

                if (!this.ValidateDuplicatedBinding(model.HostName, model.Protocol, model.Port))
                {
                    model.Certificates = this.GetCertificatesList();
                    return View(model);
                }

                if (this.ValidateCertificateAndPort(model.CertificateId, model.Port, model.Protocol))
                {
                    var webSite = new WebSite()
                    {
                        Name = model.Name.Replace(" ", string.Empty).ToLowerInvariant(),
                        Description = model.Description,
                        EnableCDNChildApplication = model.EnableCDNChildApplication,
                        EnableTestChildApplication = model.EnableTestChildApplication
                    };

                    var binding = new Binding()
                    {
                        Port = model.Port,
                        Protocol = model.Protocol,
                        HostName = model.HostName,
                        IpAddress = model.IpAddress,
                        CertificateId = model.CertificateId
                    };

                    this.webSiteRepository.CreateWebSiteWithBinding(webSite, binding);

                    return RedirectToAction("Index");
                }
                else
                {
                    model.Certificates = this.GetCertificatesList();
                    return View(model);
                }
            }
            catch
            {
                model.Certificates = this.GetCertificatesList();
                return View(model);
            }
        }
        public ActionResult Create()
        {
            var model = new WebSiteCreateModel()
            {
                Protocol = "http",
                Port = 80,
                IpAddress = "*",
                Certificates = this.GetCertificatesList(),
                EnableTestChildApplication = true,
                EnableCDNChildApplication = true
            };

            return View(model);
        }
        public void CreateWebSiteWithBindings()
        {
            Guid id = Guid.NewGuid();

            var model = new WebSiteCreateModel()
            {
                Name = "testsite" + id.ToString().ToLowerInvariant(),
                Description = "Test Description",
                Port = 80,
                IpAddress = string.Empty,
                HostName = "www.mydomain.com",
                Protocol = "http"
            };

            this.controller.Create(model);

            WebSite newsite = this.webSiteRepository.RetrieveWebSites().Where(ws => ws.Name == model.Name).FirstOrDefault();

            try
            {
                Assert.IsNotNull(newsite);
                Assert.AreEqual(model.Name, newsite.Name);
                Assert.AreEqual(model.Description, newsite.Description);

                WebSite site = this.webSiteRepository.RetrieveWebSiteWithBindings(newsite.Id);

                Assert.IsNotNull(site);
                Assert.IsNotNull(site.Bindings);
                Assert.AreEqual(1, site.Bindings.Count());

                Binding binding = site.Bindings.First();

                Assert.AreEqual(model.Port, binding.Port);
                Assert.AreEqual(site.Id, binding.WebSiteId);
                Assert.AreEqual(model.IpAddress, binding.IpAddress);
                Assert.AreEqual(model.HostName, binding.HostName);
                Assert.AreEqual(model.Protocol, binding.Protocol);
            }
            finally
            {
                string key = newsite.Id.ToString();
                this.bindingTable.DeleteEntity(this.bindingTable.Query.Where(b => b.WebSiteId == newsite.Id));
                this.webSiteTable.DeleteEntity(this.webSiteTable.Query.Where(b => b.RowKey == key));
            }
        }