public ClientConfigManagerAdminViewModel(Client currentClient, StoreFrontConfiguration currentStoreFrontConfig, UserProfile userProfile)
            : base(currentStoreFrontConfig, userProfile)
        {
            if (currentClient == null)
            {
                throw new ArgumentNullException("currentClient");
            }
            if (currentStoreFrontConfig == null)
            {
                throw new ArgumentNullException("currentStoreFrontConfig");
            }

            this.CurrentClient = currentClient;
            this.CurrentStoreFrontConfig = currentStoreFrontConfig;
            this.CurrentStoreFront = currentStoreFrontConfig.StoreFront;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public ClientConfigAdminViewModel(Client client, StoreFrontConfiguration storeFrontConfig, UserProfile userProfile, string activeTab)
     : base(storeFrontConfig, userProfile)
 {
     this.ActiveTab = activeTab;
     this.ClientId = client.ClientId;
     this.EnableNewUserRegisteredBroadcast = client.EnableNewUserRegisteredBroadcast;
     this.EnablePageViewLog = client.EnablePageViewLog;
     this.Name = client.Name;
     this.TimeZoneId = client.TimeZoneId;
     this.SendGridMailAccount = client.SendGridMailAccount;
     this.SendGridMailFromEmail = client.SendGridMailFromEmail;
     this.SendGridMailFromName = client.SendGridMailFromName;
     this.SendGridMailPassword = client.SendGridMailPassword;
     this.TwilioFromPhone = client.TwilioFromPhone;
     this.TwilioSid = client.TwilioSid;
     this.TwilioSmsFromEmail = client.TwilioSmsFromEmail;
     this.TwilioSmsFromName = client.TwilioSmsFromName;
     this.TwilioToken = client.TwilioToken;
     this.UseSendGridEmail = client.UseSendGridEmail;
     this.UseTwilioSms = client.UseTwilioSms;
 }
Ejemplo n.º 4
0
        public static ValueListItem CreateValueListItemFastAdd(this IGstoreDb db, ValueListEditAdminViewModel viewModel, string fastAddName, Client client, UserProfile userProfile)
        {
            if (string.IsNullOrWhiteSpace(fastAddName))
            {
                throw new ArgumentNullException("fastAddName");
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (userProfile == null)
            {
                throw new ArgumentNullException("userProfile");
            }

            ValueListItem newRecord = db.ValueListItems.Create();

            newRecord.Client = client;
            newRecord.ClientId = client.ClientId;
            newRecord.CreateDateTimeUtc = DateTime.UtcNow;
            newRecord.CreatedBy = userProfile;
            newRecord.CreatedBy_UserProfileId = userProfile.UserProfileId;
            newRecord.Description = fastAddName;
            newRecord.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            newRecord.IsPending = false;
            newRecord.Name = fastAddName;
            newRecord.IsInteger = false;
            newRecord.IntegerValue = null;
            newRecord.IsString = true;
            newRecord.StringValue = fastAddName;
            newRecord.Order = (viewModel.ValueListItems == null ? 100 : (viewModel.ValueListItems.Count == 0 ? 100 : (viewModel.ValueListItems.Max(vli => vli.Order) + 100)));
            newRecord.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            newRecord.ValueList = viewModel.ValueList;
            newRecord.ValueListId = viewModel.ValueListId;
            newRecord.UpdateAuditFields(userProfile);

            newRecord = db.ValueListItems.Add(newRecord);
            db.SaveChanges();

            return newRecord;
        }
 public void FillListsIfEmpty(Client client, StoreFront storeFront)
 {
 }
Ejemplo n.º 6
0
 public static void SetDefaultsForNew(this Theme theme, Client client)
 {
     if (client != null)
     {
         theme.Client = client;
         theme.ClientId = client.ClientId;
         theme.Order = client.Themes.Count == 0 ? 100 : client.Themes.Max(wf => wf.Order) + 10;
         theme.Name = "New Theme";
         bool nameIsDirty = client.Themes.Any(t => t.Name.ToLower() == theme.Name.ToLower());
         if (nameIsDirty)
         {
             int index = 1;
             do
             {
                 index++;
                 theme.Name = "New Theme " + index;
                 nameIsDirty = client.Themes.Any(t => t.Name.ToLower() == theme.Name.ToLower());
             } while (nameIsDirty);
         }
     }
     else
     {
         theme.Name = "New Theme";
         theme.Order = 100;
     }
     theme.Description = theme.Name;
     theme.IsPending = false;
     theme.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
     theme.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
 }
Ejemplo n.º 7
0
        public static void SetDefaultsForNew(this ValueList valueList, Client client)
        {
            valueList.Name = "New Value List";
            if (client != null)
            {
                valueList.ClientId = client.ClientId;
                valueList.Client = client;
                valueList.Order = valueList.Client.ValueLists.Count == 0 ? 100 : valueList.Client.ValueLists.Max(vl => vl.Order) + 10;
                if (client.ValueLists.Any(vl => vl.Name.ToLower() == valueList.Name.ToLower()))
                {
                    bool nameIsDirty = true;
                    int index = 1;
                    do
                    {
                        index ++;
                        valueList.Name = "New Value List " + index;
                        nameIsDirty = client.ValueLists.Any(vl => vl.Name.ToLower() == valueList.Name.ToLower());
                    } while (nameIsDirty);
                }
            }

            valueList.Description = valueList.Name;
            valueList.IsPending = false;
            valueList.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            valueList.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
        }
Ejemplo n.º 8
0
        public static void SetDefaultsForNew(this UserProfile profile, Client client, StoreFront storeFront)
        {
            if (client != null)
            {
                profile.Client = client;
                profile.ClientId = client.ClientId;
                profile.TimeZoneId = client.TimeZoneId;
            }

            if (storeFront != null)
            {
                profile.StoreFront = storeFront;
                profile.StoreFrontId = storeFront.StoreFrontId;
                StoreFrontConfiguration storeFrontConfig = storeFront.CurrentConfigOrAny();
                if (storeFrontConfig != null)
                {
                    profile.TimeZoneId = storeFrontConfig.TimeZoneId;
                }
            }

            profile.EntryDateTime = DateTime.UtcNow;
            profile.IsPending = true;
            profile.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            profile.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
        }
 public void FillListsIfEmpty(Client client)
 {
     if (this.ValueListSelectList == null)
     {
         this.ValueListSelectList = client.ValueLists.AsQueryable().ToSelectList(this.ValueListId).ToList();
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Dupe-safe uses PageTemplate.ViewName to prevent dupes
        /// </summary>
        private static List<PageTemplate> CreateSeedPageTemplates(this IGstoreDb storeDb, string virtualPath, Client client)
        {
            if (storeDb == null)
            {
                throw new ArgumentNullException("db");
            }
            if (string.IsNullOrEmpty(virtualPath))
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            string path = string.Empty;
            if (HttpContext.Current == null)
            {
                string assemblyPath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
                string directoryName = System.IO.Path.GetDirectoryName(assemblyPath).Replace("GStore\\GStoreData\\", "GStore\\GStoreWeb\\");
                path = System.IO.Path.Combine(directoryName, "..\\.." + virtualPath.TrimStart('~').Replace('/', '\\')).Replace("%20", " ");
                if (!System.IO.Directory.Exists(path))
                {
                    throw new ApplicationException("Page Templates folder could not be found in file system at path: " + path + ". Please run the web site first to populate the database.");
                }
            }
            else
            {
                path = HttpContext.Current.Server.MapPath(virtualPath);
            }

            if (!System.IO.Directory.Exists(path))
            {
                throw new ApplicationException("Page Templates folder could not be found in file system web server at path: " + path + ".");
            }

            System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(path);
            IEnumerable<System.IO.FileInfo> files = folder.EnumerateFiles("Page *.cshtml");
            int counter = 0;
            List<PageTemplate> newTemplates = new List<PageTemplate>();
            foreach (System.IO.FileInfo file in files)
            {
                string name = file.Name.Substring(5, ((file.Name.Length - 5) - 7)) + " Template";
                if (!client.PageTemplates.Any(pt => pt.Name.ToLower() == name.ToLower()))
                {
                    string viewName = file.Name.Replace(".cshtml", "");
                    if (!client.PageTemplates.Any(pt => pt.ViewName.ToLower() == viewName.ToLower()))
                    {
                        counter++;
                        PageTemplate pageTemplate = storeDb.PageTemplates.Create();
                        pageTemplate.Name = name;
                        pageTemplate.ViewName = viewName;
                        pageTemplate.Order = 2000 + counter;
                        if (name.ToLower() == "custom html page template")
                        {
                            pageTemplate.Order = 9000 + counter;
                        }
                        pageTemplate.Description = pageTemplate.Name;
                        pageTemplate.IsPending = false;
                        pageTemplate.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                        pageTemplate.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
                        pageTemplate.Client = client;
                        pageTemplate.ClientId = client.ClientId;

                        storeDb.PageTemplates.Add(pageTemplate);
                        newTemplates.Add(pageTemplate);
                    }
                }

            }
            storeDb.SaveChangesEx(true, false, false, false);

            return newTemplates;
        }
Ejemplo n.º 11
0
 public void FillListsIfEmpty(Client client, StoreFront storeFront)
 {
     this.StoreFront = storeFront;
     this.StoreFrontId = storeFront.StoreFrontId;
     this.Client = client;
     this.ClientId = client.ClientId;
 }
Ejemplo n.º 12
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(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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        protected void ValidateClientName(Client client)
        {
            Client conflict = GStoreDb.Clients.Where(c => c.ClientId != client.ClientId && c.Name.ToLower() == client.Name.ToLower()).FirstOrDefault();
            if (conflict != null)
            {
                this.ModelState.AddModelError("Name", "Client name '" + client.Name + "' is already in use for client '" + conflict.Name.ToHtml() + "' [" + conflict.ClientId + "]. Please choose a new name");
                bool nameIsDirty = true;
                string oldName = client.Name;
                int index = 1;
                while (nameIsDirty)
                {
                    index++;
                    client.Name = oldName + " " + index;
                    nameIsDirty = GStoreDb.Clients.Where(c => c.ClientId != client.ClientId && c.Name.ToLower() == client.Name.ToLower()).Any();
                }
                if (ModelState.ContainsKey("Name"))
                {
                    ModelState["Name"].Value = new ValueProviderResult(client.Name, client.Name, null);
                }

            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates sample web forms.
 /// Does not create dupes. Uses WebForm.Name to prevent dupes
 /// </summary>
 public static List<WebForm> CreateSeedWebForms(this IGstoreDb storeDb, Client client)
 {
     List<WebForm> forms = new List<WebForm>();
     WebForm registerForm = storeDb.CreateSeedWebFormRegister(client, false);
     if (registerForm != null)
     {
         forms.Add(registerForm);
     }
     WebForm contactUsForm = storeDb.CreateSeedWebFormContactUs(client, false);
     if (contactUsForm != null)
     {
         forms.Add(contactUsForm);
     }
     return forms;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Not dupe-safe
        /// </summary>
        private static PageTemplate CreateSeedPageTemplate(this IGstoreDb storeDb, string name, string viewName, Client client)
        {
            PageTemplate pageTemplate = storeDb.PageTemplates.Create();
            pageTemplate.Name = name;
            pageTemplate.Description = name;
            pageTemplate.ViewName = viewName;
            pageTemplate.IsPending = false;
            pageTemplate.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            pageTemplate.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            pageTemplate.Client = client;
            pageTemplate.ClientId = client.ClientId;
            storeDb.PageTemplates.Add(pageTemplate);
            storeDb.SaveChangesEx(true, false, false, false);

            return pageTemplate;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Not dupe-safe
        /// </summary>
        private static StoreFront CreateSeedStoreFront(this IGstoreDb storeDb, Client client, UserProfile adminProfile)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            StoreFront storeFront = storeDb.StoreFronts.Create();
            storeFront.SetDefaultsForNew(client);
            storeDb.StoreFronts.Add(storeFront);
            storeDb.SaveChangesEx(true, false, false, false);

            return storeFront;
        }
 public void FillListsIfEmpty(Client client)
 {
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Dupe-safe uses theme.FolderName to prevent dupes
        /// </summary>
        private static List<Theme> CreateSeedThemes(this IGstoreDb storeDb, string virtualPath, Client client)
        {
            string path = string.Empty;
            if (HttpContext.Current == null)
            {
                string assemblyPath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
                string directoryName = System.IO.Path.GetDirectoryName(assemblyPath).Replace("GStore\\GStoreData\\", "GStore\\GStoreWeb\\");
                path = System.IO.Path.Combine(directoryName, "..\\.." + virtualPath.TrimStart('~').Replace('/', '\\')).Replace("%20", " ");
                if (!System.IO.Directory.Exists(path))
                {
                    throw new ApplicationException("Themes folder could not be found in file system at path: " + path + ". Please run the web site first to populate the database.");
                }
            }
            else
            {
                path = HttpContext.Current.Server.MapPath(virtualPath);
            }

            if (!System.IO.Directory.Exists(path))
            {
                throw new ApplicationException("Themes folder could not be found in file system web server at path: " + path + ".");
            }
            System.IO.DirectoryInfo themesFolder = new System.IO.DirectoryInfo(path);
            IEnumerable<System.IO.DirectoryInfo> themeFolders = themesFolder.EnumerateDirectories();
            int counter = 0;
            List<Theme> newThemes = new List<Theme>();
            foreach (System.IO.DirectoryInfo themeFolder in themeFolders)
            {
                if (!client.Themes.Any(t => t.FolderName.ToLower() == themeFolder.Name.ToLower()))
                {
                    counter++;
                    Theme theme = storeDb.Themes.Create();
                    theme.Name = themeFolder.Name;
                    theme.Order = 2000 + counter;
                    theme.FolderName = themeFolder.Name;
                    theme.Description = themeFolder.Name + " theme";
                    theme.IsPending = false;
                    theme.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                    theme.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
                    theme.Client = client;
                    theme.ClientId = client.ClientId;

                    storeDb.Themes.Add(theme);
                    newThemes.Add(theme);
                }
            }
            storeDb.SaveChangesEx(true, false, false, false);

            return newThemes;
        }
Ejemplo n.º 21
0
 public void FillListsIfEmpty(Client client, StoreFront storeFront)
 {
     if (this.StoreFront == null)
     {
         this.StoreFront = storeFront;
         this.StoreFrontId = storeFront.StoreFrontId;
     }
     if (this.PageTemplateSelectList == null)
     {
         this.PageTemplateSelectList = client.PageTemplates.AsQueryable().ToSelectList(this.PageTemplateId).ToList();
     }
     if (this.ThemeSelectList == null)
     {
         this.ThemeSelectList = client.Themes.AsQueryable().ToSelectList(this.ThemeId).ToList();
     }
     if (this.WebFormSelectList == null)
     {
         this.WebFormSelectList = client.WebForms.AsQueryable().ToSelectListWithNull(this.WebFormId).ToList();
     }
     if (this.WebFormSuccessPageSelectList == null)
     {
         this.WebFormSuccessPageSelectList = storeFront.Pages.AsQueryable().ToSelectListWithNull(this.WebFormSuccessPageId).ToList();
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Not Dupe-safe
        /// </summary>
        private static WebForm CreateSeedWebForm(this IGstoreDb storeDb, string name, string description, Client client)
        {
            WebForm webForm = storeDb.WebForms.Create();
            webForm.SetDefaultsForNew(client);
            webForm.Client = client;
            webForm.Name = name;
            webForm.Description = description;
            storeDb.WebForms.Add(webForm);
            storeDb.SaveChangesEx(true, false, false, false);

            return webForm;
        }
Ejemplo n.º 23
0
        public static void SetDefaultsForNew(this PageTemplate pageTemplate, Client client)
        {
            pageTemplate.Order = 100;

            pageTemplate.Name = "New Page Template";
            if (client != null)
            {
                pageTemplate.Client = client;
                pageTemplate.ClientId = client.ClientId;
                pageTemplate.Order = client.PageTemplates.Count == 0 ? 100 : client.PageTemplates.Max(vl => vl.Order) + 10;
                if (client.PageTemplates.Any(pt => pt.Name.ToLower() == pageTemplate.Name.ToLower()))
                {
                    bool nameIsDirty = true;
                    int index = 1;
                    do
                    {
                        index++;
                        pageTemplate.Name = "New Page Template " + index;
                        nameIsDirty = client.PageTemplates.Any(pt => pt.Name.ToLower() == pageTemplate.Name.ToLower());
                    } while (nameIsDirty);
                }
            }
            pageTemplate.Description = pageTemplate.Name;
            pageTemplate.ViewName = string.Empty;
            pageTemplate.IsPending = false;
            pageTemplate.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            pageTemplate.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Dupe-safe uses WebForm.Name to prevent dupes
        /// </summary>
        private static WebForm CreateSeedWebFormContactUs(this IGstoreDb storeDb, Client client, bool returnWebFormIfExists)
        {
            string formName = "Simple Contact Form";
            if (client.WebForms.Any(wf => wf.Name.ToLower() == formName.ToLower()))
            {
                if (returnWebFormIfExists)
                {
                    return client.WebForms.Single(wf => wf.Name.ToLower() == formName.ToLower());
                }
                return null;
            }

            WebForm contactForm = storeDb.CreateSeedWebForm(formName, "Simple Contact Form", client);
            WebFormField contactName = storeDb.CreateSeedWebFormField(contactForm, "Your Name", 100, isRequired: true, helpLabelBottomText: "Please enter your Name");
            WebFormField contactEmail = storeDb.CreateSeedWebFormField(contactForm, "Your Email Address", 101, isRequired: true, helpLabelBottomText: "Please enter your Email Address", dataType: GStoreValueDataType.EmailAddress);
            WebFormField contactPhone = storeDb.CreateSeedWebFormField(contactForm, "Phone (optional)", 102, isRequired: false, helpLabelTopText: "If you would like us to reach you by phone, please enter your phone number below.");
            WebFormField contactMessage = storeDb.CreateSeedWebFormField(contactForm, "Message", 103, dataType: GStoreValueDataType.MultiLineText, isRequired: true, helpLabelTopText: "Enter a message below");

            return contactForm;
        }
Ejemplo n.º 25
0
        public static void SetDefaultsForNew(this WebForm webForm, Client client)
        {
            webForm.Order = 100;
            if (client != null)
            {
                webForm.Client = client;
                webForm.ClientId = client.ClientId;
                webForm.Order = client.WebForms.Count == 0 ? 100 : client.WebForms.Max(wf => wf.Order) + 10;
                webForm.Name = "New Web Form";
                if (client.WebForms.Any(wf => wf.Name.ToLower() == webForm.Name.ToLower()))
                {
                    bool nameIsDirty = true;
                    int index = 1;
                    do
                    {
                        index++;
                        webForm.Name = "New Web Form " + index;
                        webForm.Description = "New Web Form " + index;
                        nameIsDirty = client.WebForms.Any(wf => wf.Name.ToLower() == webForm.Name.ToLower());
                    } while (nameIsDirty);

                }
            }
            else
            {
                webForm.Name = "New Web Form";
            }

            webForm.DisplayTemplateName = "WebForm";
            webForm.LabelMdColSpan = 2;
            webForm.FieldMdColSpan = 10;
            webForm.SubmitButtonClass = "btn btn-primary";
            webForm.SubmitButtonText = "Submit";
            webForm.DisplayTemplateName = "WebForm";
            webForm.IsPending = false;
            webForm.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            webForm.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            webForm.Description = webForm.Name;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates PageTemplates for a client using the file system.
 /// Does not create duplicates. PageTemplate.ViewName (file name without .cshtml) is used to check for dupes
 /// </summary>
 public static List<PageTemplate> CreateSeedPageTemplates(this IGstoreDb storeDb, Client client)
 {
     string virtualPathToPageTemplates = "~/Views/Page";
     return storeDb.CreateSeedPageTemplates(virtualPathToPageTemplates, client);
 }
Ejemplo n.º 27
0
 public void UpdateClient(Client client)
 {
     this.Client = client;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates Themes records for the client based on the folder ~/Content/Server/Themes
 /// this does not create duplicates, themes will be checked by Theme.folderName
 /// </summary>
 public static List<Theme> CreateSeedThemes(this IGstoreDb storeDb, Client client)
 {
     string virtualPathToThemes = "~/Content/Server/Themes";
     return storeDb.CreateSeedThemes(virtualPathToThemes, client);
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Dupe-safe uses WebForm.Name to prevent dupes
        /// </summary>
        public static WebForm CreateSeedWebFormRegister(this IGstoreDb storeDb, Client client, bool returnWebFormIfExists)
        {
            string formName = "New Register Form";
            if (client.WebForms.Any(wf => wf.Name.ToLower() == formName.ToLower()))
            {
                if (returnWebFormIfExists)
                {
                    return client.WebForms.Single(wf => wf.Name.ToLower() == formName.ToLower());
                }
                return null;
            }

            WebForm registerForm = storeDb.CreateSeedWebForm(formName, "New Register Form", client);
            WebFormField customField = storeDb.CreateSeedWebFormField(registerForm, "How did you find us?", description: "How did you find us?", helpLabelBottomText: "Enter the name of the web site or person that referred you to us");
            return registerForm;
        }
Ejemplo n.º 30
0
        public static ValueList CreateValueList(this IGstoreDb db, Areas.StoreAdmin.ViewModels.ValueListEditAdminViewModel viewModel, Client client, UserProfile userProfile)
        {
            ValueList record = db.ValueLists.Create();

            record.Name = viewModel.Name;
            record.Order = viewModel.Order;
            record.Description = viewModel.Description;
            record.ClientId = client.ClientId;
            record.Client = client;
            record.IsPending = viewModel.IsPending;
            record.StartDateTimeUtc = viewModel.StartDateTimeUtc;
            record.EndDateTimeUtc = viewModel.EndDateTimeUtc;

            record.UpdateAuditFields(userProfile);

            db.ValueLists.Add(record);
            db.SaveChanges();

            return record;
        }