public ActionResult Create(Client client, bool? populateThemes, bool? populatePageTemplates, bool? populateSampleWebForms) { //check if client name or folder is already taken ValidateClientName(client); ValidateClientFolder(client); if (ModelState.IsValid) { IGstoreDb db = GStoreDb; client = db.Clients.Create(client); client.UpdateAuditFields(CurrentUserProfileOrThrow); client = db.Clients.Add(client); AddUserMessage("Client Added", "Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] created successfully!", UserMessageType.Success); db.SaveChanges(); string clientFolderVirtualPath = client.ClientVirtualDirectoryToMap(Request.ApplicationPath); try { client.CreateClientFolders(Request.ApplicationPath, Server); AddUserMessage("Client Folders Created", "Client Folders were created in '" + clientFolderVirtualPath.ToHtml(), UserMessageType.Success); } catch (Exception ex) { AddUserMessage("Error Creating Client Folders!", "There was an error creating client folders in '" + clientFolderVirtualPath.ToHtml() + "'. You will need to create the folder manually. Error: " + ex.Message.ToHtml(), UserMessageType.Warning); } if (populateThemes.HasValue && populateThemes.Value) { List<Theme> newThemes = db.CreateSeedThemes(client); AddUserMessage("Populated Themes", "New Themes added: " + newThemes.Count, UserMessageType.Success); } if (populatePageTemplates.HasValue && populatePageTemplates.Value) { List<PageTemplate> newPageTemplates = db.CreateSeedPageTemplates(client); AddUserMessage("Populated Page Templates", "New Page Templates added: " + newPageTemplates.Count, UserMessageType.Success); } if (populateSampleWebForms.HasValue && populateSampleWebForms.Value) { List<WebForm> newWebForms = db.CreateSeedWebForms(client); AddUserMessage("Populated Simple Web Forms", "New Forms added: " + newWebForms.Count, UserMessageType.Success); } return RedirectToAction("Index"); } this.BreadCrumbsFunc = html => this.ClientBreadcrumb(html, 0, false, "New"); return View(client); }
/// <summary> /// deletes all child records and returns a string summary of the records deleted /// </summary> /// <param name="client"></param> /// <returns></returns> protected string SeekAndDestroyChildRecordsNoSave(Client client, bool deleteEventLogs, bool deleteFolders) { StringBuilder output = new StringBuilder(); IGstoreDb db = GStoreDb; int clientId = client.ClientId; int deletedRecordCount = 0; int deletedMainRecords = 0; output.AppendLine("Deleting main records..."); deletedMainRecords += db.ClientRoles.DeleteRange(db.ClientRoles.Where(c => c.ClientId == clientId)); deletedMainRecords += db.ClientRoleActions.DeleteRange(db.ClientRoleActions.Where(c => c.ClientId == clientId)); deletedMainRecords += db.PageTemplates.DeleteRange(db.PageTemplates.Where(c => c.ClientId == clientId)); deletedMainRecords += db.PageTemplateSections.DeleteRange(db.PageTemplateSections.Where(c => c.ClientId == clientId)); deletedMainRecords += db.Themes.DeleteRange(db.Themes.Where(c => c.ClientId == clientId)); deletedMainRecords += db.WebForms.DeleteRange(db.WebForms.Where(c => c.ClientId == clientId)); deletedMainRecords += db.ValueLists.DeleteRange(db.ValueLists.Where(c => c.ClientId == clientId)); deletedMainRecords += db.ValueListItems.DeleteRange(db.ValueListItems.Where(c => c.ClientId == clientId)); deletedMainRecords += db.WebForms.DeleteRange(db.WebForms.Where(c => c.ClientId == clientId)); deletedMainRecords += db.WebFormFields.DeleteRange(db.WebFormFields.Where(c => c.ClientId == clientId)); output.AppendLine("Deleted " + deletedMainRecords.ToString("N0") + " main records!"); deletedRecordCount += deletedMainRecords; int deletedStoreFrontRecords = 0; output.AppendLine("Deleting storefront records..."); deletedStoreFrontRecords += db.StoreFronts.DeleteRange(db.StoreFronts.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.ClientUserRoles.DeleteRange(db.ClientUserRoles.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.Carts.DeleteRange(db.Carts.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.CartItems.DeleteRange(db.CartItems.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.CartBundles.DeleteRange(db.CartBundles.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.Discounts.DeleteRange(db.Discounts.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.NavBarItems.DeleteRange(db.NavBarItems.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.Notifications.DeleteRange(db.Notifications.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.NotificationLinks.DeleteRange(db.NotificationLinks.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.Pages.DeleteRange(db.Pages.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.PageSections.DeleteRange(db.PageSections.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.ProductCategories.DeleteRange(db.ProductCategories.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.Products.DeleteRange(db.Products.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.ProductBundles.DeleteRange(db.ProductBundles.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.ProductBundleItems.DeleteRange(db.ProductBundleItems.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.StoreBindings.DeleteRange(db.StoreBindings.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.StoreFrontConfigurations.DeleteRange(db.StoreFrontConfigurations.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.UserProfiles.DeleteRange(db.UserProfiles.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.WebFormResponses.DeleteRange(db.WebFormResponses.Where(c => c.ClientId == clientId)); deletedStoreFrontRecords += db.WebFormFieldResponses.DeleteRange(db.WebFormFieldResponses.Where(c => c.ClientId == clientId)); output.AppendLine("Deleted " + deletedStoreFrontRecords.ToString("N0") + " storefront records!"); deletedRecordCount += deletedStoreFrontRecords; if (deleteEventLogs) { int deletedEventLogs = 0; output.AppendLine("Deleting event logs..."); deletedEventLogs += db.BadRequests.DeleteRange(db.BadRequests.Where(c => c.ClientId == clientId)); deletedEventLogs += db.FileNotFoundLogs.DeleteRange(db.FileNotFoundLogs.Where(c => c.ClientId == clientId)); deletedEventLogs += db.PageViewEvents.DeleteRange(db.PageViewEvents.Where(c => c.ClientId == clientId)); deletedEventLogs += db.SecurityEvents.DeleteRange(db.SecurityEvents.Where(c => c.ClientId == clientId)); deletedEventLogs += db.SystemEvents.DeleteRange(db.SystemEvents.Where(c => c.ClientId == clientId)); deletedEventLogs += db.UserActionEvents.DeleteRange(db.UserActionEvents.Where(c => c.ClientId == clientId)); output.AppendLine("Deleted " + deletedEventLogs.ToString("N0") + " event logs!"); deletedRecordCount += deletedEventLogs; } if (deleteFolders) { output.AppendLine("Deleting Files..."); string clientFolderPath = Server.MapPath(client.ClientVirtualDirectoryToMap(Request.ApplicationPath)); output.AppendLine("Virtual Directory: '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath) + "'"); output.AppendLine("Physicial Directory: '" + clientFolderPath + "'"); output.AppendLine("Folder Exists: " + System.IO.Directory.Exists(clientFolderPath)); if (System.IO.Directory.Exists(clientFolderPath)) { try { System.IO.Directory.Delete(clientFolderPath, true); AddUserMessage("Client Folders Deleted.", "Client folder was deleted successfully.", UserMessageType.Info); output.AppendLine("Deleted Files!"); } catch (Exception) { AddUserMessage("Delete folders failed.", "Delete folders failed. You will have to delete the client folder manually.", UserMessageType.Warning); output.AppendLine("Delete files failed!"); } } else { output.AppendLine("Deleted Files!"); } } output.AppendLine("Total Records deleted: " + deletedRecordCount.ToString("N0")); return output.ToString(); }
protected string ChildRecordSummary(Client client, IGstoreDb db) { if (client == null) { throw new ArgumentNullException("client"); } if (db == null) { throw new ArgumentNullException("db"); } StringBuilder output = new StringBuilder(); int clientId = client.ClientId; output.AppendLine("--File and Child Record Summary for Client '" + client.Name.ToHtml() + " [" + client.ClientId + "]--"); output.AppendLine("--Client Linked Records--"); output.AppendLine("Client Roles: " + db.ClientRoles.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Client Role Actions: " + db.ClientRoleActions.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Page Templates: " + db.PageTemplates.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Page Template Sections: " + db.PageTemplateSections.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Themes: " + db.Themes.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Web Forms: " + db.WebForms.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Value Lists: " + db.ValueLists.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Value List Items: " + db.ValueListItems.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Web Forms: " + db.WebForms.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Web Form Fields: " + db.WebFormFields.Where(c => c.ClientId == clientId).Count()); output.AppendLine("--Store Front Linked Records--"); output.AppendLine("Store Fronts: " + db.StoreFronts.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Client User Roles: " + db.ClientUserRoles.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Carts: " + db.Carts.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Cart Items: " + db.CartItems.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Cart Bundles: " + db.CartBundles.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Discounts: " + db.Discounts.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Nav Bar Items: " + db.NavBarItems.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Notifications: " + db.Notifications.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Notification Links: " + db.NotificationLinks.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Pages: " + db.Pages.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Page Sections: " + db.PageSections.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Product Categories: " + db.ProductCategories.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Products: " + db.Products.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Product Bundles: " + db.ProductBundles.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Product Bundle Items: " + db.ProductBundleItems.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Store Bindings: " + db.StoreBindings.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Store Front Configurations: " + db.StoreFrontConfigurations.Where(c => c.ClientId == clientId).Count()); output.AppendLine("User Profiles: " + db.UserProfiles.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Web Form Responses: " + db.WebFormResponses.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Web Form FieldResponses: " + db.WebFormFieldResponses.Where(c => c.ClientId == clientId).Count()); output.AppendLine("--event logs--"); output.AppendLine("Bad Requests: " + db.BadRequests.Where(c => c.ClientId == clientId).Count()); output.AppendLine("File Not Found Logs: " + db.FileNotFoundLogs.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Page View Events: " + db.PageViewEvents.Where(c => c.ClientId == clientId).Count()); output.AppendLine("Security Events: " + db.SecurityEvents.Where(c => c.ClientId == clientId).Count()); output.AppendLine("System Events: " + db.SystemEvents.Where(c => c.ClientId == clientId).Count()); output.AppendLine("User Action Events: " + db.UserActionEvents.Where(c => c.ClientId == clientId).Count()); output.AppendLine("--File System--"); string clientFolderPath = Server.MapPath(client.ClientVirtualDirectoryToMap(Request.ApplicationPath)); output.AppendLine("Virtual Directory: '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath) + "'"); output.AppendLine("Physicial Directory: '" + clientFolderPath + "'"); output.AppendLine("Folder Exists: " + System.IO.Directory.Exists(clientFolderPath)); if (System.IO.Directory.Exists(clientFolderPath)) { output.AppendLine("SubFolders: " + System.IO.Directory.EnumerateDirectories(clientFolderPath, "*", System.IO.SearchOption.AllDirectories).Count()); output.AppendLine("Files: " + System.IO.Directory.EnumerateFiles(clientFolderPath, "*", System.IO.SearchOption.AllDirectories).Count()); } return output.ToString(); }
public ActionResult Edit(Client client, bool? populateThemes, bool? populatePageTemplates, bool? populateSampleWebForms) { ValidateClientName(client); ValidateClientFolder(client); if (ModelState.IsValid) { IGstoreDb db = GStoreDb; Client originalValues = db.Clients.Single(c => c.ClientId == client.ClientId); string originalFolderName = originalValues.Folder; string originalFolderToMap = originalValues.ClientVirtualDirectoryToMap(Request.ApplicationPath); client.UpdateAuditFields(CurrentUserProfileOrThrow); client = db.Clients.Update(client); AddUserMessage("Client Updated", "Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] updated!", UserMessageType.Success); db.SaveChanges(); if (populateThemes.HasValue && populateThemes.Value) { List<Theme> newThemes = db.CreateSeedThemes(client); AddUserMessage("Populated Themes", "New Themes added: " + newThemes.Count, UserMessageType.Success); } if (populatePageTemplates.HasValue && populatePageTemplates.Value) { List<PageTemplate> newPageTemplates = db.CreateSeedPageTemplates(client); AddUserMessage("Populated Page Templates", "New Page Templates added: " + newPageTemplates.Count, UserMessageType.Success); } if (populateSampleWebForms.HasValue && populateSampleWebForms.Value) { List<WebForm> newWebForms = db.CreateSeedWebForms(client); AddUserMessage("Populated Simple Web Forms", "New Forms added: " + newWebForms.Count, UserMessageType.Success); } string originalClientFolder = Server.MapPath(originalFolderToMap); string newClientFolder = Server.MapPath(client.ClientVirtualDirectoryToMap(Request.ApplicationPath)); if (client.Folder == originalFolderName && !System.IO.Directory.Exists(newClientFolder)) { client.CreateClientFolders(Request.ApplicationPath, Server); AddUserMessage("Folders Created", "Client folders were not found, so they were created in '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'", UserMessageType.Info); } else if (client.Folder != originalFolderName) { //detect if folder name has changed //default behavior is to move the old folder to the new name if (System.IO.Directory.Exists(originalClientFolder)) { try { System.IO.Directory.Move(originalClientFolder, newClientFolder); AddUserMessage("Folder Moved", "Client folder name was changed, so the client folder was moved from '" + originalFolderToMap.ToHtml() + "' to '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'", UserMessageType.Success); } catch (Exception ex) { AddUserMessage("Error Moving Client Folder!", "There was an error moving the client folder from '" + originalFolderToMap.ToHtml() + "' to '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'. You will need to move the folder manually. Error: " + ex.Message, UserMessageType.Warning); } } else { try { client.CreateClientFolders(Request.ApplicationPath, Server); AddUserMessage("Folders Created", "Client folders were created: " + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml(), UserMessageType.Info); } catch (Exception ex) { AddUserMessage("Error Creating Client Folders!", "There was an error creating the client folders in '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'. You will need to create the folders manually. Error: " + ex.Message, UserMessageType.Warning); } } } else { client.CreateClientFolders(Request.ApplicationPath, Server); } return RedirectToAction("Index"); } this.BreadCrumbsFunc = html => this.ClientBreadcrumb(html, client.ClientId, false); return View(client); }
/// <summary> /// Checks for a file in storefront, client, or storefront folders. Returns path to first file found or Null if file does not exist in any location /// Example: for a path of /Images/File1.png this function will check for [storefrontfolder]/Images/File1.png, if the file is found it will return the physical path /// if the file is not found, it will check [client folder]/Images/File1.png. if file is found in client folder, it will return that physical path /// If the file is not found in the client folder, it will check the server folder [/Content/Server]/Images/File1.png. If file is found that path will be returned. /// If file is not found in any of these locations, null is returned /// </summary> /// <param name="storeFront"></param> /// <param name="path">Path to file, can start with / or not, / is implied</param> /// <param name="applicationPath"></param> /// <param name="client">Client to search if file is not found in the storefront, or storefront is null</param> /// <param name="server">HTTP Server</param> /// <returns></returns> public static string ChooseFilePath(this StoreFront storeFront, Client client, string path, string applicationPath, HttpServerUtilityBase server) { string fullVirtualPath = null; string fullPath = null; if (storeFront != null && storeFront.IsActiveBubble()) { fullVirtualPath = storeFront.StoreFrontVirtualDirectoryToMap(applicationPath) + "/" + path.TrimStart('/'); fullPath = server.MapPath(fullVirtualPath); if (System.IO.File.Exists(fullPath)) { return fullPath; } } if (client != null && client.IsActiveDirect()) { fullVirtualPath = client.ClientVirtualDirectoryToMap(applicationPath) + "/" + path.TrimStart('/'); fullPath = server.MapPath(fullVirtualPath); if (System.IO.File.Exists(fullPath)) { return fullPath; } } fullVirtualPath = "~/Content/Server/" + path.TrimStart('/'); fullPath = server.MapPath(fullVirtualPath); if (!System.IO.File.Exists(fullPath)) { return null; } return fullPath; }
/// <summary> /// Checks for a file in storefront, client, or storefront folders. Returns path to first file found or Null if file does not exist in any location /// Example: for a virtua;l folder '/Images' and fileNameStart of 'File1' this function will check for [storefrontfolder]/Images/File1.*, if the file is found it will return the physical path /// if the file is not found, it will check [client folder]/Images/File1.*. if file is found in client folder, it will return that physical path /// If the file is not found in the client folder, it will check the server folder [/Content/Server]/Images/File1.*. If file is found that path will be returned. /// If file is not found in any of these locations, null is returned /// </summary> /// <param name="storeFront"></param> /// <param name="path">Path to file, can start with / or not, / is implied</param> /// <param name="applicationPath"></param> /// <param name="client">Client to search if file is not found in the storefront, or storefront is null</param> /// <param name="server">HTTP Server</param> /// <returns></returns> public static string ChooseFileNameWildcard(this StoreFront storeFront, Client client, string virtualFolder, string fileNameStart, string applicationPath, HttpServerUtilityBase server) { string virtualPath = null; string folderPath = null; if (storeFront != null && storeFront.IsActiveBubble()) { virtualPath = storeFront.StoreFrontVirtualDirectoryToMap(applicationPath) + "/" + virtualFolder.Trim('/'); folderPath = server.MapPath(virtualPath); if (System.IO.Directory.Exists(folderPath)) { IOrderedEnumerable<string> files = System.IO.Directory.GetFiles(folderPath, fileNameStart + ".*") .OrderByDescending(s => s.EndsWith(".png")) .ThenByDescending(s => s.EndsWith(".jpg")) .ThenByDescending(s => s.EndsWith(".jpeg")) .ThenByDescending(s => s.EndsWith(".gif")) .ThenByDescending(s => s.EndsWith(".pdf")) .ThenByDescending(s => s.EndsWith(".doc")) .ThenByDescending(s => s.EndsWith(".xls")) .ThenByDescending(s => s.EndsWith(".mp3")) .ThenByDescending(s => s.EndsWith(".txt")); if (files.Count() != 0) { return new System.IO.FileInfo(files.First()).Name; } } } if (client != null && client.IsActiveDirect()) { virtualPath = client.ClientVirtualDirectoryToMap(applicationPath) + "/" + virtualFolder.Trim('/'); folderPath = server.MapPath(virtualPath); if (System.IO.Directory.Exists(folderPath)) { IOrderedEnumerable<string> files = System.IO.Directory.GetFiles(folderPath, fileNameStart + ".*") .OrderByDescending(s => s.EndsWith(".png")) .ThenByDescending(s => s.EndsWith(".jpg")) .ThenByDescending(s => s.EndsWith(".jpeg")) .ThenByDescending(s => s.EndsWith(".gif")) .ThenByDescending(s => s.EndsWith(".pdf")) .ThenByDescending(s => s.EndsWith(".doc")) .ThenByDescending(s => s.EndsWith(".xls")) .ThenByDescending(s => s.EndsWith(".mp3")) .ThenByDescending(s => s.EndsWith(".txt")); if (files.Count() != 0) { return new System.IO.FileInfo(files.First()).Name; } } } virtualPath = "~/Content/Server/" + virtualFolder.Trim('/'); folderPath = server.MapPath(virtualPath); if (System.IO.Directory.Exists(folderPath)) { IOrderedEnumerable<string> serverFiles = System.IO.Directory.GetFiles(folderPath, fileNameStart + ".*") .OrderByDescending(s => s.EndsWith(".png")) .ThenByDescending(s => s.EndsWith(".jpg")) .ThenByDescending(s => s.EndsWith(".jpeg")) .ThenByDescending(s => s.EndsWith(".gif")) .ThenByDescending(s => s.EndsWith(".pdf")) .ThenByDescending(s => s.EndsWith(".doc")) .ThenByDescending(s => s.EndsWith(".xls")) .ThenByDescending(s => s.EndsWith(".mp3")) .ThenByDescending(s => s.EndsWith(".txt")); if (serverFiles.Count() != 0) { return new System.IO.FileInfo(serverFiles.First()).Name; } } return null; }