public ActionResult Create(Theme theme) { //check if Theme name or folder is dupe for this client ValidateThemeName(theme); if (ModelState.IsValid) { theme = GStoreDb.Themes.Create(theme); theme.UpdateAuditFields(CurrentUserProfileOrThrow); theme = GStoreDb.Themes.Add(theme); AddUserMessage("Theme Added", "Theme '" + theme.Name.ToHtml() + "' [" + theme.ThemeId + "] created successfully!", UserMessageType.Success); GStoreDb.SaveChanges(); return RedirectToAction("Index"); } int? clientId = null; if (theme.ClientId != default(int)) { clientId = theme.ClientId; } this.BreadCrumbsFunc = htmlHelper => this.ThemeBreadcrumb(htmlHelper, theme.ClientId, theme, false); return View(theme); }
public ActionResult Edit(Theme theme) { ValidateThemeName(theme); if (ModelState.IsValid) { theme.UpdateAuditFields(CurrentUserProfileOrThrow); theme = GStoreDb.Themes.Update(theme); AddUserMessage("Theme Updated", "Theme '" + theme.Name.ToHtml() + "' [" + theme.ThemeId + "] updated successfully!", UserMessageType.Success); GStoreDb.SaveChanges(); return RedirectToAction("Index"); } this.BreadCrumbsFunc = htmlHelper => this.ThemeBreadcrumb(htmlHelper, theme.ClientId, theme, false); return View(theme); }
protected void ValidateThemeName(Theme theme) { Theme conflict = GStoreDb.Themes.Where(t => t.ThemeId != theme.ThemeId && t.ClientId == theme.ClientId && t.Name.ToLower() == theme.Name.ToLower()).FirstOrDefault(); if (conflict != null) { this.ModelState.AddModelError("Name", "Theme name '" + theme.Name + "' is already in use for Theme '" + conflict.Name.ToHtml() + "' [" + conflict.ThemeId + "] for client '" + theme.Client.Name.ToHtml() + "' [" + theme.ClientId + "]. Please choose a new name"); bool nameIsDirty = true; string oldName = theme.Name; int index = 1; while (nameIsDirty) { index++; theme.Name = oldName + " " + index; nameIsDirty = GStoreDb.Themes.Where(t => t.ClientId == theme.ClientId && t.Name.ToLower() == theme.Name.ToLower()).Any(); } if (ModelState.ContainsKey("Name")) { ModelState["Name"].Value = new ValueProviderResult(theme.Name, theme.Name, null); } } }
/// <summary> /// Not dupe-safe /// </summary> private static StoreFrontConfiguration CreateSeedStoreFrontConfig(this IGstoreDb storeDb, StoreFront storeFront, string storeFrontName, string storeFrontFolder, UserProfile adminProfile, Theme selectedTheme) { if (storeFront == null) { throw new ArgumentNullException("storeFront"); } StoreFrontConfiguration storeFrontConfig = storeDb.StoreFrontConfigurations.Create(); storeFrontConfig.StoreFront = storeFront; storeFrontConfig.StoreFrontId = storeFront.StoreFrontId; storeFrontConfig.Name = storeFrontName; storeFrontConfig.ConfigurationName = "Default"; storeFrontConfig.Folder = storeFrontFolder; storeFrontConfig.IsPending = false; storeFrontConfig.StartDateTimeUtc = DateTime.UtcNow.AddSeconds(-1); storeFrontConfig.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); storeFrontConfig.Client = storeFront.Client; storeFrontConfig.ClientId = storeFront.ClientId; storeFrontConfig.Order = storeFront.StoreFrontConfigurations.Count == 0 ? 100 : storeFront.StoreFrontConfigurations.Max(sf => sf.Order) + 10; storeFrontConfig.TimeZoneId = storeFront.Client.TimeZoneId; storeFrontConfig.AccountAdmin = adminProfile; storeFrontConfig.RegisteredNotify = adminProfile; storeFrontConfig.WelcomePerson = adminProfile; storeFrontConfig.OrderAdmin = adminProfile; storeFrontConfig.MetaApplicationName = storeFrontName; storeFrontConfig.MetaApplicationTileColor = "#880088"; storeFrontConfig.MetaDescription = "New GStore Storefront " + storeFrontName; storeFrontConfig.MetaKeywords = "GStore Storefront " + storeFrontName; storeFrontConfig.AdminTheme = selectedTheme; storeFrontConfig.AccountTheme = selectedTheme; storeFrontConfig.ProfileTheme = selectedTheme; storeFrontConfig.NotificationsTheme = selectedTheme; storeFrontConfig.CatalogTheme = selectedTheme; storeFrontConfig.CatalogAdminTheme = selectedTheme; storeFrontConfig.DefaultNewPageTheme = selectedTheme; storeFrontConfig.CatalogPageInitialLevels = 6; storeFrontConfig.CatalogTitle = storeFrontConfig.Name + " Catalog"; storeFrontConfig.CatalogLayout = CatalogLayoutEnum.SimpleBlocked; storeFrontConfig.CatalogHeaderHtml = null; storeFrontConfig.CatalogFooterHtml = null; storeFrontConfig.CatalogRootListTemplate = CategoryListTemplateEnum.Default; storeFrontConfig.CatalogRootHeaderHtml = null; storeFrontConfig.CatalogRootFooterHtml = null; storeFrontConfig.CatalogDefaultBottomDescriptionCaption = null; storeFrontConfig.CatalogDefaultNoProductsMessageHtml = null; storeFrontConfig.CatalogDefaultProductBundleTypePlural = null; storeFrontConfig.CatalogDefaultProductBundleTypeSingle = null; storeFrontConfig.CatalogDefaultProductTypePlural = null; storeFrontConfig.CatalogDefaultProductTypeSingle = null; storeFrontConfig.CatalogDefaultSampleAudioCaption = null; storeFrontConfig.CatalogDefaultSampleDownloadCaption = null; storeFrontConfig.CatalogDefaultSampleImageCaption = null; storeFrontConfig.CatalogDefaultSummaryCaption = null; storeFrontConfig.CatalogDefaultTopDescriptionCaption = null; storeFrontConfig.NavBarCatalogMaxLevels = 6; storeFrontConfig.NavBarItemsMaxLevels = 6; storeFrontConfig.CatalogCategoryColLg = 3; storeFrontConfig.CatalogCategoryColMd = 4; storeFrontConfig.CatalogCategoryColSm = 6; storeFrontConfig.CatalogProductColLg = 2; storeFrontConfig.CatalogProductColMd = 3; storeFrontConfig.CatalogProductColSm = 6; storeFrontConfig.CatalogProductBundleColLg = 3; storeFrontConfig.CatalogProductBundleColMd = 4; storeFrontConfig.CatalogProductBundleColSm = 6; storeFrontConfig.CatalogProductBundleItemColLg = 3; storeFrontConfig.CatalogProductBundleItemColMd = 4; storeFrontConfig.CatalogProductBundleItemColSm = 6; storeFrontConfig.BlogTheme = selectedTheme; storeFrontConfig.BlogThemeId = selectedTheme.ThemeId; storeFrontConfig.BlogAdminTheme = selectedTheme; storeFrontConfig.BlogAdminThemeId = selectedTheme.ThemeId; storeFrontConfig.ChatTheme = selectedTheme; storeFrontConfig.ChatThemeId = selectedTheme.ThemeId; storeFrontConfig.ChatEnabled = true; storeFrontConfig.ChatRequireLogin = false; storeFrontConfig.HtmlFooter = storeFrontName; storeFrontConfig.HomePageUseCatalog = true; storeFrontConfig.HomePageUseBlog = false; storeFrontConfig.ShowBlogInMenu = false; storeFrontConfig.ShowAboutGStoreMenu = true; storeFrontConfig.NavBarShowRegisterLink = true; storeFrontConfig.NavBarRegisterLinkText = "Sign-Up"; storeFrontConfig.AccountLoginShowRegisterLink = true; storeFrontConfig.AccountLoginRegisterLinkText = "Sign-up"; if (HttpContext.Current == null) { storeFrontConfig.PublicUrl = "http://localhost:55520/"; } else { Uri url = HttpContext.Current.Request.Url; string publicUrl = "http://" + url.Host; if (!url.IsDefaultPort) { publicUrl += ":" + url.Port; } publicUrl += HttpContext.Current.Request.ApplicationPath; storeFrontConfig.PublicUrl = publicUrl; } storeFrontConfig.ApplyDefaultCartConfig(); storeFrontConfig.ApplyDefaultCheckoutConfig(); storeFrontConfig.ApplyDefaultOrdersConfig(); storeFrontConfig.ApplyDefaultPaymentMethodConfig(); storeFrontConfig.CheckoutTheme = selectedTheme; storeFrontConfig.OrdersTheme = selectedTheme; storeFrontConfig.CatalogTheme = selectedTheme; storeFrontConfig.OrderAdminTheme = selectedTheme; storeDb.StoreFrontConfigurations.Add(storeFrontConfig); storeDb.SaveChangesEx(true, false, false, false); return storeFrontConfig; }
protected MvcHtmlString ThemeBreadcrumb(HtmlHelper htmlHelper, int? clientId, Theme theme, bool ShowAsLink = false) { RouteValueDictionary routeData = null; string name = "(unknown)"; bool showLink = false; if (theme != null) { if (theme.ThemeId == 0) { name = "New"; } else { showLink = ShowAsLink; routeData = new RouteValueDictionary(new { id = theme.ThemeId }); name = "'" + theme.Name + "' [" + theme.ThemeId + "]"; } } return new MvcHtmlString( ThemesBreadcrumb(htmlHelper, clientId, true).ToHtmlString() + " -> " + (showLink ? htmlHelper.ActionLink(name, "Details", "ThemeSysAdmin", routeData, null).ToHtmlString() : name) ); }