示例#1
0
        /// <summary>
        /// deletes all child records and returns a string summary of the records deleted
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        protected string SeekAndDestroyChildRecordsNoSave(StoreFront storeFront, bool deleteEventLogs, bool deleteFolders)
        {
            StringBuilder output       = new StringBuilder();
            IGstoreDb     db           = GStoreDb;
            int           storeFrontId = storeFront.StoreFrontId;

            string virtualPath = null;

            if (storeFront.CurrentConfigOrAny() != null)
            {
                virtualPath = storeFront.StoreFrontVirtualDirectoryToMapAnyConfig(Request.ApplicationPath);
            }

            int deletedRecordCount = 0;

            int deletedStoreFrontRecords = 0;

            output.AppendLine("Deleting storefront records...");
            deletedStoreFrontRecords += db.StoreFronts.DeleteRange(db.StoreFronts.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.ClientUserRoles.DeleteRange(db.ClientUserRoles.Where(sf => sf.ScopeStoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.Carts.DeleteRange(db.Carts.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.CartItems.DeleteRange(db.CartItems.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.CartBundles.DeleteRange(db.CartBundles.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.Discounts.DeleteRange(db.Discounts.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.NavBarItems.DeleteRange(db.NavBarItems.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.Notifications.DeleteRange(db.Notifications.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.NotificationLinks.DeleteRange(db.NotificationLinks.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.Pages.DeleteRange(db.Pages.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.PageSections.DeleteRange(db.PageSections.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.ProductCategories.DeleteRange(db.ProductCategories.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.Products.DeleteRange(db.Products.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.ProductBundles.DeleteRange(db.ProductBundles.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.ProductBundleItems.DeleteRange(db.ProductBundleItems.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.StoreBindings.DeleteRange(db.StoreBindings.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.StoreFrontConfigurations.DeleteRange(db.StoreFrontConfigurations.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.UserProfiles.DeleteRange(db.UserProfiles.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.WebFormResponses.DeleteRange(db.WebFormResponses.Where(sf => sf.StoreFrontId == storeFrontId));
            deletedStoreFrontRecords += db.WebFormFieldResponses.DeleteRange(db.WebFormFieldResponses.Where(sf => sf.StoreFrontId == storeFrontId));
            output.AppendLine("Deleted " + deletedStoreFrontRecords.ToString("N0") + " storefront records!");
            deletedRecordCount += deletedStoreFrontRecords;

            if (deleteEventLogs)
            {
                output.AppendLine("Deleting event logs...");
                db.BadRequests.DeleteRange(db.BadRequests.Where(sf => sf.StoreFrontId == storeFrontId));
                db.FileNotFoundLogs.DeleteRange(db.FileNotFoundLogs.Where(sf => sf.StoreFrontId == storeFrontId));
                db.PageViewEvents.DeleteRange(db.PageViewEvents.Where(sf => sf.StoreFrontId == storeFrontId));
                db.SecurityEvents.DeleteRange(db.SecurityEvents.Where(sf => sf.StoreFrontId == storeFrontId));
                db.SystemEvents.DeleteRange(db.SystemEvents.Where(sf => sf.StoreFrontId == storeFrontId));
                db.UserActionEvents.DeleteRange(db.UserActionEvents.Where(sf => sf.StoreFrontId == storeFrontId));
                output.AppendLine("Deleted event logs!");
            }

            if (deleteFolders)
            {
                if (virtualPath == null)
                {
                    output.AppendLine("Warning: No store front configuration, no folder name for StoreFront files. They might not exist or have been orphaned when the configuration was deleted.");
                }
                else
                {
                    string folderPath = Server.MapPath(virtualPath);
                    output.AppendLine("Deleting Files...");
                    output.AppendLine("Virtual Directory: '" + virtualPath + "'");
                    output.AppendLine("Physicial Directory: '" + folderPath + "'");
                    output.AppendLine("Folder Exists: " + System.IO.Directory.Exists(folderPath));
                    if (System.IO.Directory.Exists(folderPath))
                    {
                        try
                        {
                            System.IO.Directory.Delete(folderPath, true);
                            AddUserMessage("Store Front Folders Deleted.", "Store Front 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 Store Front 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());
        }