예제 #1
0
        public ActionResult Edit(MiniSiteShortModel model, GridCommand command)
        {
            string storeUrl = (new Uri(_storeInformationSettings.StoreUrl)).Host;
            var    miniSite = _miniSiteService.GetMiniSiteById(model.Id);

            if (miniSite.Active != model.Active)
            {
                if (miniSite.Active)
                {
                    _miniSiteEmailSender.SendMiniSiteRejectEmail(miniSite.Id, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault().Id);
                    try
                    {
                        string result = _webHelper.DeleteWebSiteBinding(miniSite.DomainName, storeUrl);
                        SuccessNotification(result + "\nBinding deleted succesfully");
                    }
                    catch (FaultException ex)
                    {
                        if (ex.Message != "Binding not found!")
                        {
                            throw ex;
                        }
                    }
                }
                else
                {
                    _miniSiteEmailSender.SendMiniSiteAcceptEmail(miniSite.Id, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault().Id);
                    string result = _webHelper.AddWebSiteBinding(model.DomainName, storeUrl);
                    SuccessNotification(result + "\nBinding added succesfully");
                }
                miniSite.Active = model.Active;
            }
            else
            {
                if (miniSite.DomainName != model.DomainName)
                {
                    if (model.Active)
                    {
                        try
                        {
                            string result = _webHelper.DeleteWebSiteBinding(miniSite.DomainName, storeUrl);
                            SuccessNotification(result + "\nBinding deleted succesfully");
                        }
                        catch (FaultException ex)
                        {
                            if (ex.Message != "Binding not found!")
                            {
                                throw ex;
                            }
                        }
                        string res = _webHelper.AddWebSiteBinding(model.DomainName, storeUrl);
                        SuccessNotification(res + "\nBinding added succesfully");
                    }
                }
            }
            miniSite.DomainName = model.DomainName;
            _miniSiteService.UpdateMiniSite(miniSite);

            return(List(command));
        }
예제 #2
0
        public ActionResult MainSetup(MiniSiteGeneralSetupModel model)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(RedirectToRoute("HomePage"));
            }
            if (_workContext.CurrentCustomer.UserMiniSite == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!String.IsNullOrEmpty(model.DomainName) && model.UseSecondLavelDomain)
            {
                if (!Regex.IsMatch(model.DomainName, @"^[a-z|A-Z|0-9][a-z|A-Z|0-9|-]{1,61}[a-z|A-Z|0-9]$"))
                {
                    ModelState.AddModelError("DomainName", _localizationService.GetResource("Etf.Domain.Invalid"));
                }
                //model.DomainName = model.DomainName.Replace("http:\\", "");
                //model.DomainName = model.DomainName.Replace("https:\\", "");
                //model.DomainName = model.DomainName.Replace("\\", "");
                //model.DomainName = model.DomainName.Replace("/", "");
            }

            if (!String.IsNullOrEmpty(model.OwnDomain) && !model.UseSecondLavelDomain)
            {
                if (!ValidateDomain(model.OwnDomain))
                {
                    ModelState.AddModelError("OwnDomain", _localizationService.GetResource("Etf.Domain.Invalid"));
                }
                //model.OwnDomain = model.OwnDomain.Replace("http:\\", "");
                //model.OwnDomain = model.OwnDomain.Replace("https:\\", "");
                //model.OwnDomain = model.OwnDomain.Replace("\\", "");
                //model.OwnDomain = model.OwnDomain.Replace("/", "");
            }
            string storeUrl   = (new Uri(_storeInformationSettings.StoreUrl).Host);
            string domainName = model.UseSecondLavelDomain ? model.DomainName + "." + (new Uri(_storeInformationSettings.StoreUrl).Host) : model.OwnDomain;

            if (!String.IsNullOrEmpty(domainName) && domainName != _workContext.CurrentCustomer.UserMiniSite.DomainName)
            {
                domainName = domainName.ToLower();
                var miniSite = _miniSiteService.GetMiniSiteByDomain(domainName);
                if (miniSite != null && miniSite.Customer.Id != _workContext.CurrentCustomer.Id)
                {
                    ModelState.AddModelError("DomainName", "Minisite with specified domain name already exists");
                }
            }
            if (ModelState.IsValid)
            {
                var minisite = _workContext.CurrentCustomer.UserMiniSite;
                if (minisite.DomainName != domainName)
                {
                    if (minisite.Active)
                    {
                        try
                        {
                            _webHelper.DeleteWebSiteBinding(minisite.DomainName, storeUrl);
                        }
                        catch (FaultException ex)
                        {
                            if (ex.Message != "Binding not found!")
                            {
                                throw ex;
                            }
                        }
                    }
                    minisite.Active     = false;
                    minisite.DomainName = domainName.Replace("www.", "");
                }

                if (minisite.LogoId != model.LogoId)
                {
                    var    logo         = _pictureService.GetPictureById(model.LogoId);
                    string templatePath = Server.MapPath("~/Content/MiniSite/" + _workContext.CurrentCustomer.Username);
                    using (var fs = System.IO.File.OpenWrite(templatePath + @"\logo.jpg"))
                    {
                        if (logo != null)
                        {
                            var binary = _pictureService.LoadPictureBinary(logo);
                            fs.Write(binary, 0, binary.Length);
                            fs.Close();
                        }
                        else
                        {
                            fs.Write(new byte[1] {
                                0
                            }, 0, 1);
                        }
                    }

                    var pict = _pictureService.GetPictureById(minisite.LogoId);
                    if (pict != null)
                    {
                        _pictureService.DeletePicture(_pictureService.GetPictureById(minisite.LogoId));
                    }
                }
                minisite.LogoId   = model.LogoId;
                minisite.LayoutId = model.LayoutId;
                _localizedEntityService.SaveLocalizedValue(minisite.MiniSiteLayout, x => x.RootTitle, model.Title, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "en").FirstOrDefault().Id);
                _localizedEntityService.SaveLocalizedValue(minisite.MiniSiteLayout, x => x.RootTitle, model.TitleRus, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault().Id);
                minisite.MiniSiteLayout.CssTemplate = model.CssTemplateName;
                minisite.ContactEmail = model.ContactEmail;
                _miniSiteService.UpdateMiniSite(minisite);
                if (!String.IsNullOrEmpty(model.GoogleAnalytics))
                {
                    _genericAttributeService.SaveAttribute(minisite, SystemCustomerAttributeNames.Signature, model.GoogleAnalytics);
                }
                if (model.UseSecondLavelDomain)
                {
                    model.OwnDomain = null;
                }
                else
                {
                    model.DomainName = null;
                }
            }

            string tempPath = Server.MapPath("~/Content/MiniSite/Templates");

            string[] templates = Directory.GetDirectories(tempPath);
            var      names     = templates.Select(x => x.Substring(x.LastIndexOf(@"\") + 1, x.Length - x.LastIndexOf(@"\") - 1)).ToList();

            model.AviableCssTemplates = names;

            return(View(model));
        }