public static bool MoveStoreFrontFolders(this StoreFrontConfiguration config, string applicationPath, HttpServerUtilityBase server, string oldFolder, BaseController controller) { string oldFolderToMap = config.ClientVirtualDirectoryToMapToStoreFronts(applicationPath) + "/" + oldFolder; string newFolderToMap = config.StoreFrontVirtualDirectoryToMap(applicationPath); string oldFolderPath = server.MapPath(oldFolderToMap); string newFolderPath = server.MapPath(newFolderToMap); //default behavior is to move the old folder to the new name if (System.IO.Directory.Exists(oldFolderPath)) { try { System.IO.Directory.Move(oldFolderPath, newFolderPath); if (controller != null) { controller.AddUserMessage("Store Front Folder Moved", "Store Front folder was moved from '" + oldFolderToMap.ToHtml() + "' to '" + newFolderToMap.ToHtml() + "'", UserMessageType.Success); } return(true); } catch (Exception ex) { if (controller != null) { controller.AddUserMessage("Error Moving Client Folder!", "There was an error moving the client folder from '" + oldFolderToMap.ToHtml() + "' to '" + newFolderToMap.ToHtml() + "'. You will need to move the folder manually. Error: " + ex.Message, UserMessageType.Warning); } return(false); } } else { try { bool result = config.CreateStoreFrontFolders(applicationPath, server); if (result) { if (controller != null) { controller.AddUserMessage("Folders Created", "Store Front folders were created in : " + newFolderToMap.ToHtml(), UserMessageType.Info); } return(true); } return(false); } catch (Exception ex) { if (controller != null) { controller.AddUserMessage("Error Creating Store Front Folders!", "There was an error creating the Store Front folders in '" + newFolderToMap.ToHtml() + "'. You will need to create the folders manually. Error: " + ex.Message, UserMessageType.Warning); } return(false); } } }
public ActionResult Edit(StoreFront storeFront, bool?createDefaultConfig, int?themeId, bool?populateProducts, bool?populateDiscounts, bool?populatePages) { if ((storeFront.CurrentConfigOrAny() == null) && !(createDefaultConfig ?? false) && (populatePages ?? false)) { ModelState.AddModelError("createDefaultConfig", "You must select check the Create Default Configuration box when using Load Simple Sample Pages"); } if ((storeFront.CurrentConfigOrAny() == null) && !(createDefaultConfig ?? false) && (populateProducts ?? false)) { ModelState.AddModelError("createDefaultConfig", "You must select check the Create Default Configuration box when using Load Sample Products"); } if (ModelState.IsValid) { IGstoreDb db = GStoreDb; storeFront.UpdateAuditFields(CurrentUserProfileOrThrow); storeFront = db.StoreFronts.Update(storeFront); db.SaveChanges(); if (createDefaultConfig.HasValue && createDefaultConfig.Value) { ActionResult configResult = CreateConfig(storeFront.StoreFrontId, themeId); } if (storeFront.CurrentConfigOrAny() != null) { StoreFrontConfiguration config = storeFront.CurrentConfigOrAny(); if (!config.StoreFrontFoldersAllExist(Request.ApplicationPath, Server)) { config.CreateStoreFrontFolders(Request.ApplicationPath, Server); AddUserMessage("Store Front Folders Sync'd", "Store Front Folder sync'd or created for StoreFront '" + config.Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] for client '" + storeFront.Client.Name.ToHtml() + "' [" + storeFront.ClientId + "]", UserMessageType.Success); } } AddUserMessage("Store Front Updated", "Store Front [" + storeFront.StoreFrontId + "] for client '" + storeFront.Client.Name.ToHtml() + "' [" + storeFront.ClientId + "] was updated successfully!", UserMessageType.Success); if (populateDiscounts ?? false) { db.CreateSeedDiscounts(storeFront); AddUserMessage("Populated Discounts", "Sample Discounts are Loaded", UserMessageType.Success); } if (populateProducts ?? false) { if (storeFront.CurrentConfigOrAny() == null) { AddUserMessage("Could not Populate Products", "Could not populate products. Store Front does not have an active configuration", UserMessageType.Danger); } else { db.CreateSeedProducts(storeFront.CurrentConfigOrAny()); AddUserMessage("Populated Products", "Sample Products, Bundles, and Categories are Loaded", UserMessageType.Success); } } if (populatePages ?? false) { if (storeFront.CurrentConfigOrAny() == null) { AddUserMessage("Could not Populate Pages", "Could not populate Pages. Store front does not have an active configuration", UserMessageType.Danger); } else { db.CreateSeedPages(storeFront.CurrentConfigOrAny()); AddUserMessage("Populated Pages", "Simple Pages with Menu Links are Loaded", UserMessageType.Success); } } return(RedirectToAction("Index")); } this.BreadCrumbsFunc = htmlHelper => this.StoreFrontBreadcrumb(htmlHelper, storeFront.ClientId, storeFront, false); return(View(storeFront)); }
/// <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")); }