public void CreateWebSiteWithBinding(WebSite webSite, Binding binding)
        {
            binding.WebSiteId = webSite.Id;

            this.webSiteTable.AddEntity(webSite.ToRow());
            this.bindingTable.AddEntity(binding.ToRow());
        }
        private WebSite CreateWebSiteWithBindings(int nbindings)
        {
            Guid id = Guid.NewGuid();
            var bindings = new List<Binding>();

            var site = new WebSite(id)
            {
                Name = "Test Web Site " + id.ToString(),
                Description = "Description Test Web Site " + id.ToString()
            };

            var binding = new Binding()
            {
                Protocol = "http",
                IpAddress = string.Empty,
                Port = 80,
                HostName = "www.test0.com"
            };

            this.repository.CreateWebSiteWithBinding(site, binding);
            bindings.Add(binding);

            for (int k = 1; k < nbindings; k++)
            {
                var otherBinding = new Binding()
                {
                    Protocol = "http",
                    IpAddress = string.Empty,
                    Port = 80 + k,
                    HostName = string.Format("www.test{0}.com", k)
                };

                this.repository.AddBindingToWebSite(site.Id, otherBinding);
                bindings.Add(otherBinding);
            }

            site.Bindings = bindings;

            return site;
        }
        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);
            }
        }
 private string GetBindingUrl(Binding b)
 {
     return this.GetUrl(b.Protocol, b.HostName, b.Port);
 }
        public ActionResult CreateBinding(Guid webSiteId, BindingModel model)
        {
            try
            {
                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 binding = new Binding()
                    {
                        Port = model.Port,
                        Protocol = model.Protocol,
                        HostName = model.HostName,
                        IpAddress = model.IpAddress,
                        CertificateId = model.CertificateId
                    };

                    this.webSiteRepository.AddBindingToWebSite(webSiteId, binding);

                    return RedirectToAction("Edit", new { id = webSiteId });
                }
                else
                {
                    model.Certificates = this.GetCertificatesList();
                    return View(model);
                }
            }
            catch
            {
                model.Certificates = this.GetCertificatesList();
                return View(model);
            }
        }
 public void EditBinding(Binding binding)
 {
     this.bindingTable.AddOrUpdateEntity(binding.ToRow());
 }
 public void AddBindingToWebSite(WebSite webSite, Binding binding)
 {
     binding.WebSiteId = webSite.Id;
     this.bindingTable.AddEntity(binding.ToRow());
 }
        public Certificate RetrieveCertificateForBinding(Binding binding)
        {
            if (!binding.CertificateId.HasValue)
            {
                return null;
            }

            string key = binding.CertificateId.Value.ToString();

            Certificate certificate = this.certificateTable.Query.Where(c => c.RowKey == key).FirstOrDefault().ToModel();

            if (certificate != null)
            {
                certificate.Content = this.certificateBlobContainer.GetBytes(certificate.Id.ToString());
            }

            binding.Certificate = certificate;

            return certificate;
        }