Beispiel #1
0
        /// <summary>
        /// Creates a configuration where there is none for a storefront
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult CreateConfig(int?id, int?themeId)
        {
            if (!id.HasValue || id.Value == 0)
            {
                return(HttpBadRequest("storeFrontId is null or 0"));
            }
            StoreFront storeFront = GStoreDb.StoreFronts.FindById(id.Value);

            if (storeFront == null)
            {
                return(HttpBadRequest("storeFront not found by id: " + id.Value));
            }

            StoreFrontConfiguration configToCopyFrom = storeFront.CurrentConfigOrAny();
            StoreFrontConfiguration newConfig        = GStoreDb.StoreFrontConfigurations.Create();

            if (configToCopyFrom != null)
            {
                newConfig = newConfig.UpdateValuesFromEntity(configToCopyFrom);
                newConfig.StoreFrontConfigurationId = 0;
                newConfig.StoreFront = storeFront;
                newConfig.Client     = storeFront.Client;
            }
            else
            {
                UserProfile profile = GStoreDb.SeedAutoMapUserBestGuess();
                if (profile == null)
                {
                    AddUserMessage("Config Create Error!", "No users found to link to new configuration for client '" + storeFront.Client.Name + "' [" + storeFront.ClientId + "]. Method: SeedAutoMapUserBestGuess"
                                   + "<br/><a href=\"" + Url.Action("Create", "UserProfileSysAdmin") + "\">Click HERE to create a new user profile for this client.</a>", UserMessageType.Danger);
                    return(RedirectToAction("Create", "UserProfileSysAdmin", new { clientId = storeFront.ClientId, storeFrontId = storeFront.StoreFrontId }));
                }

                Theme theme = null;
                if (themeId.HasValue && themeId != 0)
                {
                    theme = storeFront.Client.Themes.SingleOrDefault(t => t.ThemeId == themeId.Value);
                }
                if (theme == null)
                {
                    theme = storeFront.Client.Themes.FirstOrDefault(t => t.FolderName.ToLower() == Settings.AppDefaultThemeFolderName.ToLower());
                }
                if (theme == null)
                {
                    theme = storeFront.Client.Themes.AsQueryable().ApplyDefaultSort().FirstOrDefault();
                }

                if (theme == null)
                {
                    AddUserMessage("Config Create Error!", "No Themes found to link to new configuration for client '" + storeFront.Client.Name + "' [" + storeFront.ClientId + "]. Method: FirstTheme"
                                   + "<br/> <a href=\"" + Url.Action("Create", "ThemeSysAdmin") + "\">Click HERE to create a new theme for this client.</a>", UserMessageType.Danger);
                    return(RedirectToAction("Create", "ThemeSysAdmin", new { clientId = storeFront.ClientId }));
                }

                newConfig.StoreFront   = storeFront;
                newConfig.StoreFrontId = storeFront.StoreFrontId;
                newConfig.SetDefaultsForNew(storeFront.Client);
                newConfig.AccountAdmin        = profile;
                newConfig.WelcomePerson       = profile;
                newConfig.OrderAdmin          = profile;
                newConfig.RegisteredNotify    = profile;
                newConfig.AccountTheme        = theme;
                newConfig.AdminTheme          = theme;
                newConfig.CartTheme           = theme;
                newConfig.BlogTheme           = theme;
                newConfig.BlogAdminTheme      = theme;
                newConfig.ChatTheme           = theme;
                newConfig.CheckoutTheme       = theme;
                newConfig.CatalogTheme        = theme;
                newConfig.CatalogAdminTheme   = theme;
                newConfig.DefaultNewPageTheme = theme;
                newConfig.NotificationsTheme  = theme;
                newConfig.OrdersTheme         = theme;
                newConfig.OrderAdminTheme     = theme;
                newConfig.ProfileTheme        = theme;
                newConfig.ApplyDefaultCartConfig();
                newConfig.ApplyDefaultCheckoutConfig();
                newConfig.ApplyDefaultOrdersConfig();
            }

            newConfig = GStoreDb.StoreFrontConfigurations.Add(newConfig);
            GStoreDb.SaveChanges();

            string storeFrontRootFolder = newConfig.StoreFront.StoreFrontVirtualDirectoryToMap(Request.ApplicationPath);

            string clientFrontFolderVirtualPath = storeFront.ClientVirtualDirectoryToMap(Request.ApplicationPath);
            string storeFrontFolderVirtualPath  = newConfig.StoreFrontVirtualDirectoryToMapThisConfig(Request.ApplicationPath);

            if (!System.IO.Directory.Exists(Server.MapPath(clientFrontFolderVirtualPath)))
            {
                storeFront.Client.CreateClientFolders(Request.ApplicationPath, Server);
                AddUserMessage("Client Folders Created.", "Client Folders Created for Client '" + storeFront.Client.Name.ToHtml() + "' [" + storeFront.ClientId + "] in '" + clientFrontFolderVirtualPath.ToHtml() + "'.", UserMessageType.Success);
            }

            if (!System.IO.Directory.Exists(Server.MapPath(storeFrontFolderVirtualPath)))
            {
                bool result = newConfig.CreateStoreFrontFolders(Request.ApplicationPath, Server);
                if (result)
                {
                    AddUserMessage("Store Front Folders Created.", "Store Front Folders Created for New Configuration '" + newConfig.ConfigurationName.ToHtml() + "' [" + newConfig.StoreFrontConfigurationId + "] in '" + storeFrontFolderVirtualPath.ToHtml() + "'.", UserMessageType.Success);
                }
                else
                {
                    AddUserMessage("File system Error!", "Store Front Folders could not be created for New Configuration '" + newConfig.ConfigurationName.ToHtml() + "' [" + newConfig.StoreFrontConfigurationId + "] in '" + storeFrontFolderVirtualPath.ToHtml() + "'.", UserMessageType.Success);
                }
            }

            AddUserMessage("Store Front Configuration Created.", "Store Front Configuration '" + newConfig.ConfigurationName.ToHtml() + "' [" + newConfig.StoreFrontConfigurationId + "] created successfully for Store Front '" + newConfig.Name.ToHtml() + "' [" + newConfig.StoreFrontId + "].", UserMessageType.Success);

            return(RedirectToAction("Index"));
        }