Exemple #1
0
        public ActionResult MainSetup()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(RedirectToRoute("HomePage"));
            }
            if (_workContext.CurrentCustomer.UserMiniSite == null)
            {
                return(RedirectToRoute("HomePage"));
            }
            if (!_workContext.CurrentCustomer.UserMiniSite.Active)
            {
                return(RedirectToAction("MyProfile", "Customer"));
            }
            var model    = new MiniSiteGeneralSetupModel();
            var miniSite = _workContext.CurrentCustomer.UserMiniSite;

            if (miniSite == null)
            {
                return(RedirectToAction("Add"));
            }

            model.LayoutId             = miniSite.LayoutId;
            model.ContactEmail         = miniSite.ContactEmail;
            model.CssTemplateName      = miniSite.MiniSiteLayout.CssTemplate;
            model.UseSecondLavelDomain = miniSite.DomainName.IndexOf(new Uri(_storeInformationSettings.StoreUrl).Host) > 0 ? true : false;
            if (model.UseSecondLavelDomain)
            {
                model.DomainName = miniSite.DomainName.Replace("." + (new Uri(_storeInformationSettings.StoreUrl).Host), "");
            }
            else
            {
                model.OwnDomain = miniSite.DomainName;
            }
            model.Title           = miniSite.MiniSiteLayout.GetLocalized(x => x.RootTitle, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "en").FirstOrDefault().Id);
            model.TitleRus        = miniSite.MiniSiteLayout.GetLocalized(x => x.RootTitle, _languageService.GetAllLanguages().Where(x => x.UniqueSeoCode == "ru").FirstOrDefault().Id);
            model.LogoId          = miniSite.LayoutId;
            model.LogoId          = miniSite.LogoId;
            model.GoogleAnalytics = miniSite.GetAttribute <string>(SystemCustomerAttributeNames.Signature);
            string templatePath = Server.MapPath("~/Content/MiniSite/Templates");

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

            model.AviableCssTemplates = names;

            return(View(model));
        }
Exemple #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));
        }