public ActionResult SendTestEmail() { UserProfile profile = CurrentUserProfileOrThrow; if (!profile.AspNetIdentityUser().EmailConfirmed) { AddUserMessage("Test Email not sent", "You must confirm your email address before you can receive email.", UserMessageType.Warning); return(RedirectToAction("Index")); } Client client = CurrentClientOrThrow; StoreFront storeFront = CurrentStoreFrontOrThrow; string subject = "Test Email from " + storeFront.CurrentConfig().Name + " - " + Request.BindingHostName(); string textBody = "Test Email from " + storeFront.CurrentConfig().Name + " - " + Request.BindingHostName(); string htmlBody = "Test Email from " + storeFront.CurrentConfig().Name + " - " + Request.BindingHostName(); bool result = this.SendEmail(profile.Email, profile.FullName, subject, textBody, htmlBody); if (result) { AddUserMessage("Test Email Sent!", "Test Email was sent to '" + profile.Email.ToHtml() + "'.", UserMessageType.Success); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestEmail, profile.Email, true, emailAddress: profile.Email); } else { AddUserMessage("Test Email not sent", "Test Email was NOT sent. This store does not have Email send activated.", UserMessageType.Warning); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestEmail, "Email Disabled", false, emailAddress: profile.Email); } return(RedirectToAction("Index")); }
public List <SelectListItem> StoreFrontConfigList(StoreFront storeFront) { if (storeFront == null) { throw new ArgumentNullException("storeFront"); } StoreFrontConfiguration currentConfig = storeFront.CurrentConfig(); int currentconfigId = 0; if (currentConfig != null) { currentconfigId = currentConfig.StoreFrontConfigurationId; } List <SelectListItem> list = new List <SelectListItem>(); List <StoreFrontConfiguration> orderedConfigs = storeFront.StoreFrontConfigurations.AsQueryable().ApplyDefaultSort().ToList(); List <SelectListItem> listItemQuery = orderedConfigs.Select(c => new SelectListItem() { Value = c.StoreFrontConfigurationId.ToString(), Text = (c.StoreFrontConfigurationId == currentconfigId ? " [Current Active] " : "") + c.ConfigurationName + " [" + c.StoreFrontConfigurationId + "]" + (c.IsPending ? " [INACTIVE]" : " [" + c.StartDateTimeUtc.ToLocalTime().ToShortDateString() + " to " + c.EndDateTimeUtc.ToLocalTime().ToShortDateString() + "]"), Selected = (c.StoreFrontConfigurationId == currentconfigId) }).ToList(); list.AddRange(listItemQuery.ToList()); return(list); }
public List<SelectListItem> StoreFrontConfigList(StoreFront storeFront) { if (storeFront == null) { throw new ArgumentNullException ("storeFront"); } StoreFrontConfiguration currentConfig = storeFront.CurrentConfig(); int currentconfigId = 0; if (currentConfig != null) { currentconfigId = currentConfig.StoreFrontConfigurationId; } List<SelectListItem> list = new List<SelectListItem>(); List<StoreFrontConfiguration> orderedConfigs = storeFront.StoreFrontConfigurations.AsQueryable().ApplyDefaultSort().ToList(); List<SelectListItem> listItemQuery = orderedConfigs.Select(c => new SelectListItem() { Value = c.StoreFrontConfigurationId.ToString(), Text = (c.StoreFrontConfigurationId == currentconfigId ? " [Current Active] " : "") + c.ConfigurationName + " [" + c.StoreFrontConfigurationId + "]" + (c.IsPending ? " [INACTIVE]" : " [" + c.StartDateTimeUtc.ToLocalTime().ToShortDateString() + " to " + c.EndDateTimeUtc.ToLocalTime().ToShortDateString() + "]"), Selected = (c.StoreFrontConfigurationId == currentconfigId) }).ToList(); list.AddRange(listItemQuery.ToList()); return list; }
public CatalogViewModel(StoreFront storeFront, List <TreeNode <ProductCategory> > categoryTree, int maxLevels, ProductCategory currentCategoryOrNull, Product currentProductOrNull, ProductBundle currentProductBundleOrNull, ProductBundleItem currentProductBundleItemOrNull, TreeNode <ProductCategory> currentCategoryNodeOrNull = null, List <Product> productListOrNull = null, List <ProductBundle> productBundleListOrNull = null) { this.StoreFront = storeFront; this.StoreFrontConfig = storeFront.CurrentConfig(); this.CategoryTree = categoryTree; this.MaxLevels = maxLevels; this._currentCategoryNode = currentCategoryNodeOrNull; this.CurrentCategoryOrNull = currentCategoryOrNull; this.CurrentProductOrNull = currentProductOrNull; this.CurrentProductBundleOrNull = currentProductBundleOrNull; this.CurrentProductBundleItemOrNull = currentProductBundleItemOrNull; this._products = productListOrNull; this._bundles = productBundleListOrNull; }
public static StoreFrontConfiguration CurrentConfigOrAny(this StoreFront storefront) { if (storefront == null) { throw new ArgumentNullException("storeFront"); } if (storefront.StoreFrontConfigurations == null || storefront.StoreFrontConfigurations.Count == 0) { return(null); } StoreFrontConfiguration activeConfig = storefront.CurrentConfig(); if (activeConfig != null) { return(activeConfig); } return(storefront.StoreFrontConfigurations.OrderBy(c => c.Order).FirstOrDefault()); }
public static StoreBinding AutoMapBindingSeedBestGuessStoreFront(this SystemAdminBaseController controller) { StoreBinding binding = controller.GStoreDb.AutoMapBinding(controller); StoreFront storeFront = binding.StoreFront; string message = string.Empty; if (Settings.AppEnableBindingAutoMapCatchAll) { message = " to catch-all binding"; } else { message = " to current Url"; } string storeFrontName = storeFront.CurrentConfig() == null ? "No config found for Store Front Id: " + storeFront.StoreFrontId : storeFront.CurrentConfig().Name; controller.AddUserMessage("AutoMapBindingSeedBestGuessStoreFront Success!", "Auto-mapped" + message.ToHtml() + " store binding to best guess store front '" + storeFrontName.ToHtml() + "' [" + storeFront.StoreFrontId + "]", AppHtmlHelpers.UserMessageType.Success); return(binding); }
public ActionResult SendTestSms() { UserProfile profile = CurrentUserProfileOrThrow; string smsPhone = profile.AspNetIdentityUser().PhoneNumber; if (string.IsNullOrWhiteSpace(smsPhone)) { AddUserMessage("Test Text Message not sent", "You must add a phone number before you can receive SMS text messages.", UserMessageType.Warning); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestSms, "No Phone Number", false, smsPhone: smsPhone); return(RedirectToAction("Index")); } if (!profile.AspNetIdentityUser().PhoneNumberConfirmed) { AddUserMessage("Test Text Message not sent", "You must confirm your phone number before you can receive SMS text messages.", UserMessageType.Warning); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestSms, "Phone Number Not Confirmed", false, smsPhone: smsPhone); return(RedirectToAction("Index")); } Client client = CurrentClientOrThrow; StoreFront storeFront = CurrentStoreFrontOrThrow; string textBody = "Test Text Message from " + storeFront.CurrentConfig().Name + " - " + Request.BindingHostName(); bool result = this.SendSms(smsPhone, textBody); if (result) { AddUserMessage("Test Text Message Sent!", "Test SMS Text Message was sent to '" + profile.AspNetIdentityUser().PhoneNumber.ToHtml() + "'.", UserMessageType.Success); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestSms, smsPhone, true, smsPhone: smsPhone); } else { AddUserMessage("Test Text Message Not Sent!", "Test Text Message was NOT sent. This store does not have SMS Text send activated.", UserMessageType.Warning); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Profile, UserActionActionEnum.Profile_SendTestSms, "Sms Disabled", false, smsPhone: smsPhone); } return(RedirectToAction("Index")); }
public ActionResult Delete(int?id, string Tab) { if (!id.HasValue) { return(HttpBadRequest("PageId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; Page page = storeFront.Pages.Where(p => p.PageId == id.Value).SingleOrDefault(); if (page == null) { AddUserMessage("Page not found", "Sorry, the page you are trying to Delete cannot be found. Page id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); return(RedirectToAction("Manager")); } PageEditViewModel viewModel = new PageEditViewModel(page, isStoreAdminEdit: true, isReadOnly: true, isDeletePage: true, activeTab: Tab); return(View("Delete", viewModel)); }
public ActionResult Edit(int?id, ProductBundleEditAdminViewModel viewModel, List <ProductBundleItemEditAdminViewModel> bundleItems, string saveAndView, string addProductId, int?removeItemId, int?removeAltCategoryId) { if (viewModel == null || viewModel.ProductBundleId == 0) { return(HttpBadRequest("Product Bundle Id = 0")); } if (viewModel.ProductBundleId != (id ?? 0)) { return(HttpBadRequest("Product Bundle Id mismatch Request id: " + (id.HasValue ? id.Value.ToString() : "(null)") + " viewModel.ProductBundleId: " + viewModel.ProductBundleId)); } StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow; StoreFront storeFront = config.StoreFront; bool nameIsValid = GStoreDb.ValidateProductBundleUrlName(this, viewModel.UrlName, storeFront.StoreFrontId, storeFront.ClientId, viewModel.ProductBundleId); ProductBundle productBundle = storeFront.ProductBundles.SingleOrDefault(p => p.ProductBundleId == viewModel.ProductBundleId); if (productBundle == null) { AddUserMessage("Product Bundle not found", "Sorry, the Product Bundle you are trying to edit cannot be found. Product Bundle Id: [" + viewModel.ProductBundleId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewBundleByName", "Catalog", new { area = "", urlName = viewModel.UrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Bundles_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } if (bundleItems != null && bundleItems.Count != 0) { if (!bundleItems.All(bi => productBundle.ProductBundleItems.Any(pb => pb.ProductBundleItemId == bi.ProductBundleItemId))) { return(HttpBadRequest("bundle items do not all have the same ProductBundleId")); } } if (!string.IsNullOrEmpty(addProductId)) { int productIdToAdd = 0; if (!int.TryParse(addProductId, out productIdToAdd)) { return(HttpBadRequest("product id invalid")); } if (productBundle.ProductBundleItems.Any(pbi => pbi.ProductId == productIdToAdd)) { AddUserMessage("Product already exists in bundle", "Product id " + productIdToAdd + " already exists in this bundle.", UserMessageType.Info); } else { ProductBundleItem newItem = GStoreDb.CreateProductBundleItemFastAdd(productBundle, productIdToAdd, storeFront, CurrentUserProfileOrThrow, 1); AddUserMessage("Added Item!", "Product '" + newItem.Product.Name.ToHtml() + "' [" + newItem.ProductId + "] was added to the bundle '" + productBundle.Name.ToHtml() + "' [" + productBundle.ProductBundleId + "]", UserMessageType.Info); } } if (ModelState.IsValid && nameIsValid) { bool removedItem = false; ProcessFileUploads(viewModel, storeFront); productBundle = GStoreDb.UpdateProductBundle(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Product Bundle updated successfully!", "Product Bundle updated successfully. Product Bundle '" + productBundle.Name.ToHtml() + "' [" + productBundle.ProductBundleId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (bundleItems != null && bundleItems.Count != 0) { GStoreDb.UpdateProductBundleItems(productBundle, bundleItems, storeFront, CurrentUserProfileOrThrow); } if (removeItemId.HasValue && removeItemId.Value != 0) { removedItem = true; RemoveItem(productBundle, removeItemId.Value); } if (removeAltCategoryId.HasValue && removeAltCategoryId.Value != 0) { ProductCategoryAltProductBundle removeAltProductBundle = productBundle.CategoryAltBundles.SingleOrDefault(p => p.ProductCategoryId == removeAltCategoryId.Value); if (removeAltProductBundle == null) { AddUserMessage("Error removing cross-sell Category", "Category Id [" + removeAltCategoryId.Value + "] could not be found in bundle alt categories.", UserMessageType.Danger); } else { string oldName = removeAltProductBundle.Category.Name; GStoreDb.ProductCategoryAltProductBundles.Delete(removeAltProductBundle); GStoreDb.SaveChanges(); AddUserMessage("Removed cross-sell Catergory", oldName.ToHtml() + " was removed.", UserMessageType.Info); } } if (removeAltCategoryId.HasValue) { return(RedirectToAction("Edit", new { id = productBundle.ProductBundleId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (!string.IsNullOrEmpty(addProductId) || removedItem) { return(RedirectToAction("Edit", new { id = productBundle.ProductBundleId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (!string.IsNullOrWhiteSpace(saveAndView)) { return(RedirectToAction("Details", new { id = productBundle.ProductBundleId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewBundleByName", "Catalog", new { area = "", urlName = viewModel.UrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Bundles_Manager)) { return(RedirectToAction("Manager", new { ProductCategoryId = productBundle.ProductCategoryId })); } return(RedirectToAction("Index", "CatalogAdmin")); } if (Request.HasFiles()) { AddUserMessage("Files not uploaded", "You must correct the form values below and re-upload your files", UserMessageType.Danger); } viewModel.UpdateProductBundle(productBundle); ViewData.Add("ReturnToFrontEnd", viewModel.ReturnToFrontEnd); return(View("CreateOrEdit", viewModel)); }
public static bool ActivateStoreFrontClientBindingAndConfig(this SystemAdminBaseController controller, StoreBinding binding) { if (controller == null) { throw new NullReferenceException("controller"); } if (binding == null) { throw new ArgumentNullException("binding"); } if (binding.StoreFront.CurrentConfigOrAny() == null) { controller.AddUserMessage("Store Front Config Not Found", "No Configuration was found for Store Front Id: " + binding.StoreFrontId, AppHtmlHelpers.UserMessageType.Warning); return(false); } StoreFrontConfiguration config = binding.StoreFront.CurrentConfigOrAny(); if (!config.IsActiveDirect()) { config.IsPending = false; config.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); config.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); config = controller.GStoreDb.StoreFrontConfigurations.Update(config); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Store Config", "Activated Store Front Configuration '" + config.ConfigurationName.ToHtml() + "' [" + config.StoreFrontConfigurationId + "]", AppHtmlHelpers.UserMessageType.Info); } if (!binding.IsActiveDirect()) { binding.IsPending = false; binding.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); binding.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); controller.GStoreDb.StoreBindings.Update(binding); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Store Binding", "Activated Store Binding Id: " + binding.StoreBindingId, AppHtmlHelpers.UserMessageType.Info); } if (!binding.Client.IsActiveDirect()) { Client client = binding.Client; client.IsPending = false; client.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); client.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); controller.GStoreDb.Clients.Update(client); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Client", "Activated Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]", AppHtmlHelpers.UserMessageType.Info); } if (!binding.StoreFront.IsActiveDirect()) { StoreFront storeFront = binding.StoreFront; storeFront.IsPending = false; storeFront.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); storeFront.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); controller.GStoreDb.StoreFronts.Update(storeFront); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Store Front", "Activated Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.ClientId + "]", AppHtmlHelpers.UserMessageType.Info); } return(true); }
public static bool ActivateStoreFrontOnly(this SystemAdminBaseController controller, int storeFrontId) { StoreFront storeFront = controller.GStoreDb.StoreFronts.FindById(storeFrontId); if (storeFront == null) { controller.AddUserMessage("Activate Store Front Failed!", "Store Front not found by id: " + storeFrontId, AppHtmlHelpers.UserMessageType.Danger); return(false); } if (storeFront.IsActiveDirect()) { controller.AddUserMessage("Store Front is already active.", "Store Front is already active. id: " + storeFrontId, AppHtmlHelpers.UserMessageType.Info); return(false); } storeFront.IsPending = false; storeFront.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); storeFront.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); controller.GStoreDb.StoreFronts.Update(storeFront); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Store Front", "Activated Store Front '" + (storeFront.CurrentConfig() == null ? "" : storeFront.CurrentConfig().Name.ToHtml()) + "' [" + storeFront.ClientId + "]" + " - Client '" + storeFront.Client.Name.ToHtml() + "' [" + storeFront.Client.ClientId + "]", AppHtmlHelpers.UserMessageType.Info); return(true); }
public ActionResult DeleteConfirmed(int?id) { if (!id.HasValue) { return(HttpBadRequest("PageId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; Page page = storeFront.Pages.Where(p => p.PageId == id.Value).SingleOrDefault(); if (page == null) { AddUserMessage("Page not found", "Sorry, the page you are trying to Delete cannot be found. It may have been deleted already. Page id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); return(RedirectToAction("Manager")); } string pageName = page.Name; try { List <PageSection> sectionsToDelete = page.Sections.ToList(); foreach (PageSection section in sectionsToDelete) { GStoreDb.PageSections.Delete(section); } List <NavBarItem> navBarItemsToDelete = page.NavBarItems.ToList(); foreach (NavBarItem navBarItem in navBarItemsToDelete) { GStoreDb.NavBarItems.Delete(navBarItem); } bool deleted = GStoreDb.Pages.DeleteById(id.Value); GStoreDb.SaveChanges(); if (deleted) { AddUserMessage("Page Deleted", "Page '" + pageName.ToHtml() + "' [" + id + "] was deleted successfully. Sections deleted: " + sectionsToDelete.Count + " Menu Items Deleted: " + navBarItemsToDelete.Count + ".", UserMessageType.Success); return(RedirectToAction("Manager")); } AddUserMessage("Page Delete Error", "There was an error deleting Page '" + pageName.ToHtml() + "' [" + id + "]. It may have already been deleted.", UserMessageType.Warning); return(RedirectToAction("Manager")); } catch (Exception ex) { string errorMessage = "There was an error deleting Page '" + pageName + "' [" + id + "]. <br/>Error: '" + ex.GetType().FullName + "'"; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Page Delete Error", errorMessage.ToHtml(), UserMessageType.Danger); return(RedirectToAction("Manager")); } }
public ActionResult AdvancedDeleteConfirmed(int?id, bool returnToManager = false) { if (!id.HasValue) { return(HttpBadRequest("NavBarItemId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; NavBarItem navBarItem = storeFront.NavBarItems.Where(p => p.NavBarItemId == id.Value).SingleOrDefault(); if (navBarItem == null) { AddUserMessage("Menu Item not found", "Sorry, the Menu Item you are trying to Delete cannot be found. It may have been deleted already. Menu Item Id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (returnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } string navBarItemName = navBarItem.Name; try { bool deleted = GStoreDb.NavBarItems.DeleteById(id.Value); GStoreDb.SaveChanges(); if (deleted) { AddUserMessage("Menu Item Deleted", "Menu Item '" + navBarItemName.ToHtml() + "' [" + id + "] was deleted successfully.", UserMessageType.Success); if (returnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } AddUserMessage("Menu Item Delete Error", "There was an error deleting Menu Item '" + navBarItemName.ToHtml() + "' [" + id + "]. It may have already been deleted.", UserMessageType.Warning); if (returnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } catch (Exception ex) { string errorMessage = "There was an error deleting Menu Item '" + navBarItemName + "' [" + id + "]. <br/>Error: '" + ex.GetType().FullName + "'"; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Menu Item Delete Error", errorMessage.ToHtml(), UserMessageType.Danger); if (returnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } }
public ActionResult Delete(int?id, string Tab, bool returnToFrontEnd = false) { if (!id.HasValue) { return(HttpBadRequest("ProductId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; Product product = storeFront.Products.Where(p => p.ProductId == id.Value).SingleOrDefault(); if (product == null) { AddUserMessage("Product not found", "Sorry, the Product you are trying to Delete cannot be found. Product id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } ProductEditAdminViewModel viewModel = new ProductEditAdminViewModel(product, CurrentUserProfileOrThrow, isDeletePage: true, activeTab: Tab); viewModel.ReturnToFrontEnd = returnToFrontEnd; ViewData.Add("ReturnToFrontEnd", returnToFrontEnd); return(View("Delete", viewModel)); }
public ActionResult PreviewDigitalDownload(int?id) { if (!id.HasValue) { return(HttpBadRequest("ProductId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; Product product = storeFront.Products.Where(p => p.ProductId == id.Value).SingleOrDefault(); if (product == null) { AddUserMessage("Product not found", "Sorry, the Product you are trying to view cannot be found. Product Id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } if (string.IsNullOrEmpty(product.DigitalDownloadFileName)) { string errorMessage = "There is no Digital Download File linked to this product"; return(View("DigitalDownload_Error", new DigitalDownloadFileError(product, errorMessage))); } string filePath = product.DigitalDownloadFilePath(Request.ApplicationPath, RouteData, Server); if (string.IsNullOrEmpty(filePath)) { string errorMessage = "Digital Download File '" + product.DigitalDownloadFileName + "' could not be found in store front, client, or server digital download files.\n" + "Be sure file exists, and it is located in the file system 'DigitalDownload/Products/[file name]"; return(View("DigitalDownload_Error", new DigitalDownloadFileError(product, errorMessage))); } string mimeType = MimeMapping.GetMimeMapping(filePath); return(new FilePathResult(filePath, mimeType) { FileDownloadName = product.DigitalDownloadFileName }); }
public virtual PartialViewResult UpdatePageAjax(int?PageId, PageEditViewModel pageEditViewModel) { if (!PageId.HasValue) { return(HttpBadRequestPartial("Page id parameter is null")); } if (pageEditViewModel.PageId == 0) { return(HttpBadRequestPartial("Page id in viewmodel is 0")); } if (PageId.Value != pageEditViewModel.PageId) { return(HttpBadRequestPartial("Page id mismatch. PageId Parameter " + PageId.Value + " != " + pageEditViewModel.PageId)); } if (pageEditViewModel.PageTemplateId == 0) { ModelState.AddModelError("PageTemplateId", "Page Template must be selected"); } if (pageEditViewModel.ThemeId == 0) { ModelState.AddModelError("ThemeId", "Page Theme must be selected"); } if (string.IsNullOrWhiteSpace(pageEditViewModel.Url)) { ModelState.AddModelError("Url", "Url is invalid. Example: '/' or '/Contact'"); } else { if (pageEditViewModel.Url.Trim('/').Trim() == ".") { ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Example: '/' or '/Contact'"); } if (pageEditViewModel.Url.Contains('?')) { ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Question mark is not allowed in URL. Example: '/' or '/Contact'"); } } StoreFront storeFront = CurrentStoreFrontOrThrow; bool urlIsValid = GStoreDb.ValidatePageUrl(this, pageEditViewModel.Url, storeFront.StoreFrontId, storeFront.ClientId, pageEditViewModel.PageId); if (urlIsValid && ModelState.IsValid) { Page page = null; try { page = GStoreDb.UpdatePage(pageEditViewModel, this, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Page Changes Saved!", "Page '" + page.Name.ToHtml() + "' [" + page.PageId + "] saved successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); pageEditViewModel = new PageEditViewModel(page, isStoreAdminEdit: true, activeTab: pageEditViewModel.ActiveTab); return(PartialView("_PageEditPartial", pageEditViewModel)); } catch (Exception ex) { string errorMessage = "An error occurred while saving your changes to page '" + pageEditViewModel.Name + "' Url: '" + pageEditViewModel.Url + "' [" + pageEditViewModel.PageId + "] for Store Front: '" + storeFront.CurrentConfig().Name + "' [" + storeFront.StoreFrontId + "] \nError: '" + ex.GetType().FullName + "'"; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): '" + ex.ToString() + "'"; } AddUserMessage("Error Saving Page!", errorMessage.ToHtmlLines(), UserMessageType.Danger); ModelState.AddModelError("Ajax", errorMessage); } } else { AddUserMessage("Page Edit Error", "There was an error with your entry for page " + pageEditViewModel.Name.ToHtml() + " [" + pageEditViewModel.PageId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it.", UserMessageType.Danger); } pageEditViewModel.IsStoreAdminEdit = true; pageEditViewModel.FillListsIfEmpty(CurrentClientOrThrow, CurrentStoreFrontOrThrow); return(PartialView("_PageEditPartial", pageEditViewModel)); }
public virtual ActionResult Create(PageEditViewModel pageEditViewModel) { if (pageEditViewModel.PageTemplateId == 0) { ModelState.AddModelError("PageTemplateId", "Page Template must be selected"); } if (pageEditViewModel.ThemeId == 0) { ModelState.AddModelError("ThemeId", "Page Theme must be selected"); } if (string.IsNullOrWhiteSpace(pageEditViewModel.Url)) { ModelState.AddModelError("Url", "Url is blank. Enter a valid Url for this page. Example: '/' or '/Contact'"); } else { if (pageEditViewModel.Url.Trim('/').Trim() == ".") { ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Example: '/' or '/Contact'"); } if (pageEditViewModel.Url.Contains('?')) { ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Question mark is not allowed in URL. Example: '/' or '/Contact'"); } } StoreFront storeFront = CurrentStoreFrontOrThrow; bool urlIsValid = GStoreDb.ValidatePageUrl(this, pageEditViewModel.Url, storeFront.StoreFrontId, storeFront.ClientId, null); if (urlIsValid && ModelState.IsValid) { try { Page page = null; page = GStoreDb.CreatePage(pageEditViewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Page Created!", "Page '" + page.Name.ToHtml() + "' [" + page.PageId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (pageEditViewModel.CreateMenuItemWithPage) { NavBarItem navBarItem = GStoreDb.CreateNavBarItemForPage(page, CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow); AddUserMessage("Site Menu Updated!", "Page '" + page.Name.ToHtml() + "' [" + page.PageId + "] was added to the site menu for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); } if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Pages_View)) { return(RedirectToAction("Details", new { id = page.PageId })); } return(RedirectToAction("Manager")); } catch (Exception ex) { string errorMessage = "An error occurred while Creating page '" + pageEditViewModel.Name + "' Url: '" + pageEditViewModel.Url + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Error Creating Page!", errorMessage.ToHtmlLines(), UserMessageType.Danger); ModelState.AddModelError("Ajax", errorMessage); } } else { AddUserMessage("Page Create Error", "There was an error with your entry for new page '" + pageEditViewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger); } pageEditViewModel.IsStoreAdminEdit = true; pageEditViewModel.FillListsIfEmpty(storeFront.Client, storeFront); pageEditViewModel.IsCreatePage = true; return(View("Create", pageEditViewModel)); }
public ActionResult DeleteConfirmed(int?id, int?moveToCategoryId, bool returnToFrontEnd = false) { if (!id.HasValue) { return(HttpBadRequest("ProductCategoryId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; ProductCategory productCategory = storeFront.ProductCategories.Where(pc => pc.ProductCategoryId == id.Value).SingleOrDefault(); if (productCategory == null) { AddUserMessage("Category not found", "Sorry, the Category you are trying to Delete cannot be found. It may have been deleted already. Category Id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } return(RedirectToAction("Manager")); } string productCategoryName = productCategory.Name; try { ProductCategory moveToCategory = null; if (moveToCategoryId.HasValue) { moveToCategory = storeFront.ProductCategories.Where(pc => pc.ProductCategoryId == moveToCategoryId.Value).SingleOrDefault(); } if (moveToCategory != null) { List <ProductCategory> childCategories = GStoreDb.ProductCategories.Where(pc => pc.ProductCategoryId == productCategory.ProductCategoryId).ToList(); foreach (ProductCategory childCategory in childCategories) { childCategory.ParentCategoryId = moveToCategory.ProductCategoryId; GStoreDb.ProductCategories.Update(childCategory); } List <ProductBundle> childBundles = productCategory.ProductBundles.ToList(); foreach (ProductBundle bundle in childBundles) { bundle.ProductCategoryId = moveToCategory.ProductCategoryId; GStoreDb.ProductBundles.Update(bundle); } List <ProductCategoryAltProductBundle> childAltBundles = productCategory.CategoryAltProductBundles.ToList(); foreach (ProductCategoryAltProductBundle altBundle in childAltBundles) { altBundle.ProductCategoryId = moveToCategory.ProductCategoryId; GStoreDb.ProductCategoryAltProductBundles.Update(altBundle); } List <Product> childProducts = productCategory.Products.ToList(); foreach (Product product in childProducts) { product.ProductCategoryId = moveToCategory.ProductCategoryId; GStoreDb.Products.Update(product); } List <ProductCategoryAltProduct> childAltProducts = productCategory.CategoryAltProducts.ToList(); foreach (ProductCategoryAltProduct altProduct in childAltProducts) { altProduct.ProductCategoryId = moveToCategory.ProductCategoryId; GStoreDb.ProductCategoryAltProducts.Update(altProduct); } AddUserMessage("Child Items are being moved to Category '" + moveToCategory.Name.ToHtml() + "' [" + moveToCategory.ProductCategoryId + "]", "Category '" + productCategoryName.ToHtml() + "' [" + id + "] was deleted successfully.", UserMessageType.Success); } bool deleted = GStoreDb.ProductCategories.DeleteById(id.Value); GStoreDb.SaveChanges(); if (deleted) { AddUserMessage("Category Deleted", "Category '" + productCategoryName.ToHtml() + "' [" + id + "] was deleted successfully.", UserMessageType.Success); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } return(RedirectToAction("Manager")); } AddUserMessage("Category Delete Error", "There was an error deleting Category '" + productCategoryName.ToHtml() + "' [" + id + "]. It may have already been deleted.", UserMessageType.Warning); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } return(RedirectToAction("Manager")); } catch (Exception ex) { string errorMessage = "There was an error deleting Category '" + productCategoryName + "' [" + id + "]. <br/>Error: '" + ex.GetType().FullName + "'"; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Category Delete Error", errorMessage.ToHtml(), UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } return(RedirectToAction("Manager")); } }
public ActionResult Delete(int?id, string Tab, bool returnToFrontEnd = false) { if (!id.HasValue) { return(HttpBadRequest("ProductCategoryId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; ProductCategory productCategory = storeFront.ProductCategories.Where(pc => pc.ProductCategoryId == id.Value).SingleOrDefault(); if (productCategory == null) { AddUserMessage("Category not found", "Sorry, the Category you are trying to Delete cannot be found. Category id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = productCategory.UrlName })); } return(RedirectToAction("Manager")); } CategoryEditAdminViewModel viewModel = new CategoryEditAdminViewModel(productCategory, CurrentUserProfileOrThrow, isDeletePage: true, activeTab: Tab); viewModel.ReturnToFrontEnd = returnToFrontEnd; return(View("Delete", viewModel)); }
public ActionResult Edit(CategoryEditAdminViewModel viewModel, string Tab, string saveAndView, int?addCrossSellProductId, int?addCrossSellBundleId, int?removeAltProductId, int?removeAltBundleId) { StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow; StoreFront storeFront = config.StoreFront; bool nameIsValid = GStoreDb.ValidateProductCategoryUrlName(this, viewModel.UrlName, storeFront.StoreFrontId, storeFront.ClientId, viewModel.ProductCategoryId); ProductCategory productCategory = storeFront.ProductCategories.SingleOrDefault(pc => pc.ProductCategoryId == viewModel.ProductCategoryId); if (productCategory == null) { AddUserMessage("Category not found", "Sorry, the Category you are trying to edit cannot be found. Category Id: [" + viewModel.ProductCategoryId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = productCategory.UrlName })); } return(RedirectToAction("Manager")); } if (ModelState.IsValid && nameIsValid) { ProcessFileUploads(viewModel, storeFront); productCategory = GStoreDb.UpdateProductCategory(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Category updated successfully!", "Category updated successfully. Category '" + productCategory.Name.ToHtml() + "' [" + productCategory.ProductCategoryId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (addCrossSellProductId.HasValue && addCrossSellProductId.Value != 0) { if (!productCategory.CategoryAltProducts.Any(p => p.ProductId == addCrossSellProductId.Value)) { Product crossSellProduct = storeFront.Products.SingleOrDefault(p => p.ProductId == addCrossSellProductId.Value); if (crossSellProduct == null) { AddUserMessage("Error adding cross-sell " + productCategory.ProductTypeSingleOrSystemDefault(config).ToHtml(), "Product Id [" + addCrossSellProductId.Value + "] could not be found in products.", UserMessageType.Danger); } else { ProductCategoryAltProduct newAltProduct = GStoreDb.CreateProductCategoryAltProductFastAdd(productCategory, crossSellProduct, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Added cross-sell " + productCategory.ProductTypeSingleOrSystemDefault(config).ToHtml(), newAltProduct.Product.Name.ToHtml() + " added", UserMessageType.Info); } } } if (addCrossSellBundleId.HasValue && addCrossSellBundleId.Value != 0) { if (!productCategory.CategoryAltProductBundles.Any(b => b.ProductBundleId == addCrossSellBundleId.Value)) { ProductBundle crossSellProductBundle = storeFront.ProductBundles.SingleOrDefault(p => p.ProductBundleId == addCrossSellBundleId.Value); if (crossSellProductBundle == null) { AddUserMessage("Error adding cross-sell " + productCategory.BundleTypeSingleOrSystemDefault(config).ToHtml(), "Product Bundle Id [" + addCrossSellBundleId.Value + "] could not be found in product bundles.", UserMessageType.Danger); } else { ProductCategoryAltProductBundle newAltProductBundle = GStoreDb.CreateProductCategoryAltProductBundleFastAdd(productCategory, crossSellProductBundle, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Added cross-sell " + productCategory.BundleTypeSingleOrSystemDefault(config).ToHtml(), newAltProductBundle.ProductBundle.Name.ToHtml() + " added", UserMessageType.Info); } } } if (removeAltProductId.HasValue && removeAltProductId.Value != 0) { ProductCategoryAltProduct removeAltProduct = productCategory.CategoryAltProducts.SingleOrDefault(p => p.ProductId == removeAltProductId.Value); if (removeAltProduct == null) { AddUserMessage("Error removing cross-sell " + productCategory.ProductTypeSingleOrSystemDefault(config).ToHtml(), "Product Id [" + removeAltProductId.Value + "] could not be found in category alt products.", UserMessageType.Danger); } else { string oldName = removeAltProduct.Product.Name; GStoreDb.ProductCategoryAltProducts.Delete(removeAltProduct); GStoreDb.SaveChanges(); AddUserMessage("Removed cross-sell " + productCategory.ProductTypeSingleOrSystemDefault(config).ToHtml(), oldName.ToHtml() + " was removed.", UserMessageType.Info); } } if (removeAltBundleId.HasValue && removeAltBundleId.Value != 0) { ProductCategoryAltProductBundle removeAltBundle = productCategory.CategoryAltProductBundles.SingleOrDefault(p => p.ProductBundleId == removeAltBundleId.Value); if (removeAltBundle == null) { AddUserMessage("Error removing cross-sell " + productCategory.BundleTypeSingleOrSystemDefault(config).ToHtml(), "Product Bundle Id [" + removeAltBundleId.Value + "] could not be found in category alt product bundles.", UserMessageType.Danger); } else { string oldName = removeAltBundle.ProductBundle.Name; GStoreDb.ProductCategoryAltProductBundles.Delete(removeAltBundle); GStoreDb.SaveChanges(); AddUserMessage("Removed cross-sell " + productCategory.BundleTypeSingleOrSystemDefault(config).ToHtml(), oldName.ToHtml() + " was removed.", UserMessageType.Info); } } if (addCrossSellProductId.HasValue || addCrossSellBundleId.HasValue || removeAltProductId.HasValue || removeAltBundleId.HasValue) { return(RedirectToAction("Edit", new { id = productCategory.ProductCategoryId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (!string.IsNullOrWhiteSpace(saveAndView)) { return(RedirectToAction("Details", new { id = productCategory.ProductCategoryId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = productCategory.UrlName })); } return(RedirectToAction("Manager")); } if (this.ModelState.ContainsKey("UrlName")) { ModelState["UrlName"].Value = new ValueProviderResult(viewModel.UrlName, viewModel.UrlName, null); } if (Request.HasFiles()) { AddUserMessage("Files not uploaded", "You must correct the form values below and re-upload your files", UserMessageType.Danger); } viewModel.FillListsIfEmpty(storeFront.Client, storeFront); viewModel.UpdateProductCategoryAndParent(productCategory); return(View("CreateOrEdit", viewModel)); }
public ActionResult Create(NavBarItemEditAdminViewModel viewModel) { StoreFront storeFront = CurrentStoreFrontOrThrow; bool nameIsValid = GStoreDb.ValidateNavBarItemName(this, viewModel.Name, storeFront.StoreFrontId, storeFront.ClientId, null); if (nameIsValid && ModelState.IsValid) { try { NavBarItem navBarItem = GStoreDb.CreateNavBarItem(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Menu Item Created!", "Menu Item '" + navBarItem.Name.ToHtml() + "' [" + navBarItem.NavBarItemId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); return(RedirectToAction("Manager")); } catch (Exception ex) { string errorMessage = "An error occurred while Creating Menu Item '" + viewModel.Name + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Error Creating Menu Item!", errorMessage.ToHtmlLines(), UserMessageType.Danger); ModelState.AddModelError("Ajax", errorMessage); } } else { AddUserMessage("Create Menu Item Error", "There was an error with your entry for new menu item '" + viewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger); } viewModel.FillListsIfEmpty(storeFront.Client, storeFront); viewModel.UpdateParentNavBarItem(CurrentStoreFrontOrThrow.NavBarItems.SingleOrDefault(nb => nb.NavBarItemId == viewModel.ParentNavBarItemId)); viewModel.IsSimpleCreatePage = true; return(View("Create", viewModel)); }
public virtual ActionResult AdvancedCreate(NavBarItemEditAdminViewModel navBarItemEditViewModel) { StoreFront storeFront = CurrentStoreFrontOrThrow; bool nameIsValid = GStoreDb.ValidateNavBarItemName(this, navBarItemEditViewModel.Name, storeFront.StoreFrontId, storeFront.ClientId, null); if (nameIsValid && ModelState.IsValid) { try { NavBarItem navBarItem = GStoreDb.CreateNavBarItem(navBarItemEditViewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Menu Item Created!", "Menu Item '" + navBarItem.Name.ToHtml() + "' [" + navBarItem.NavBarItemId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.NavBarItems_View)) { return(RedirectToAction("AdvancedDetails", new { id = navBarItem.NavBarItemId, ReturnToManager = navBarItemEditViewModel.ReturnToManager })); } return(RedirectToAction("AdvancedManager")); } catch (Exception ex) { string errorMessage = "An error occurred while Creating Menu Item '" + navBarItemEditViewModel.Name + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Error Creating Menu Item!", errorMessage.ToHtmlLines(), UserMessageType.Danger); ModelState.AddModelError("Ajax", errorMessage); } } else { AddUserMessage("Create Menu Item Error", "There was an error with your entry for new menu item '" + navBarItemEditViewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger); } navBarItemEditViewModel.FillListsIfEmpty(storeFront.Client, storeFront); navBarItemEditViewModel.IsCreatePage = true; return(View("AdvancedCreate", navBarItemEditViewModel)); }
public ActionResult Edit(ProductEditAdminViewModel viewModel, string saveAndView, int?addToBundleId, string addTobundle, int?addToBundleQty, int?removeAltCategoryId) { StoreFront storeFront = CurrentStoreFrontOrThrow; bool nameIsValid = GStoreDb.ValidateProductUrlName(this, viewModel.UrlName, storeFront.StoreFrontId, storeFront.ClientId, viewModel.ProductId); Product product = storeFront.Products.SingleOrDefault(p => p.ProductId == viewModel.ProductId); if (product == null) { AddUserMessage("Product not found", "Sorry, the Product you are trying to edit cannot be found. Product Id: [" + viewModel.ProductId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewProductByName", "Catalog", new { area = "", urlName = viewModel.UrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } if (ModelState.IsValid && nameIsValid) { ProcessFileUploads(viewModel, storeFront); bool addedToBundle = false; if (!string.IsNullOrEmpty(addTobundle) && addToBundleId.HasValue && addToBundleId.Value != 0) { ProductBundleItem newItem = GStoreDb.CreateProductBundleItemFastAdd(addToBundleId.Value, product, storeFront, CurrentUserProfileOrThrow, addToBundleQty ?? 1); addedToBundle = true; } product = GStoreDb.UpdateProduct(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Product updated successfully!", "Product updated successfully. Product '" + product.Name.ToHtml() + "' [" + product.ProductId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (removeAltCategoryId.HasValue && removeAltCategoryId.Value != 0) { ProductCategoryAltProduct removeAltProduct = product.CategoryAltProducts.SingleOrDefault(p => p.ProductCategoryId == removeAltCategoryId.Value); if (removeAltProduct == null) { AddUserMessage("Error removing cross-sell Category", "Category Id [" + removeAltCategoryId.Value + "] could not be found in product alt categories.", UserMessageType.Danger); } else { string oldName = removeAltProduct.Category.Name; GStoreDb.ProductCategoryAltProducts.Delete(removeAltProduct); GStoreDb.SaveChanges(); AddUserMessage("Removed cross-sell Catergory", oldName.ToHtml() + " was removed.", UserMessageType.Info); } } if (removeAltCategoryId.HasValue) { return(RedirectToAction("Edit", new { id = product.ProductId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (!string.IsNullOrWhiteSpace(saveAndView) || addedToBundle) { return(RedirectToAction("Details", new { id = product.ProductId, returnToFrontEnd = viewModel.ReturnToFrontEnd, Tab = viewModel.ActiveTab })); } if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewProductByName", "Catalog", new { area = "", urlName = viewModel.UrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager", new { productCategoryId = viewModel.ProductCategoryId })); } return(RedirectToAction("Index", "CatalogAdmin")); } if (Request.HasFiles()) { AddUserMessage("Files not uploaded", "You must correct the form values below and re-upload your files", UserMessageType.Danger); } viewModel.UpdateProduct(product); ViewData.Add("ReturnToFrontEnd", viewModel.ReturnToFrontEnd); return(View("CreateOrEdit", viewModel)); }
public ActionResult AdvancedEdit(NavBarItemEditAdminViewModel viewModel, string Tab) { StoreFront storeFront = CurrentStoreFrontOrThrow; bool nameIsValid = GStoreDb.ValidateNavBarItemName(this, viewModel.Name, storeFront.StoreFrontId, storeFront.ClientId, viewModel.NavBarItemId); NavBarItem navBarItem = storeFront.NavBarItems.SingleOrDefault(nb => nb.NavBarItemId == viewModel.NavBarItemId); if (navBarItem == null) { AddUserMessage("Menu Item not found", "Sorry, the Menu Item you are trying to edit cannot be found. Menu Item Id: [" + viewModel.NavBarItemId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (viewModel.ReturnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } if (ModelState.IsValid && nameIsValid) { navBarItem = GStoreDb.UpdateNavBarItem(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Menu Item updated successfully!", "Menu Item updated successfully. Menu Item '" + navBarItem.Name.ToHtml() + "' [" + navBarItem.NavBarItemId + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (viewModel.ReturnToManager) { return(RedirectToAction("Manager")); } else { return(RedirectToAction("AdvancedManager")); } } return(View("AdvancedEdit", viewModel)); }
public ActionResult DeleteConfirmed(int?id, bool returnToFrontEnd = false) { if (!id.HasValue) { return(HttpBadRequest("ProductId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; Product product = storeFront.Products.Where(p => p.ProductId == id.Value).SingleOrDefault(); if (product == null) { AddUserMessage("Product not found", "Sorry, the Product you are trying to Delete cannot be found. It may have been deleted already. Product Id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("Index", "Catalog", new { area = "" })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } string productName = product.Name; string categoryUrlName = product.Category.UrlName; try { bool deleted = GStoreDb.Products.DeleteById(id.Value); GStoreDb.SaveChanges(); if (deleted) { AddUserMessage("Product Deleted", "Product '" + productName.ToHtml() + "' [" + id + "] was deleted successfully.", UserMessageType.Success); if (returnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = categoryUrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } AddUserMessage("Product Delete Error", "There was an error deleting Product '" + productName.ToHtml() + "' [" + id + "]. It may have already been deleted.", UserMessageType.Warning); if (returnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = categoryUrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } catch (Exception ex) { string errorMessage = "There was an error deleting Product '" + productName + "' [" + id + "]. <br/>Error: '" + ex.GetType().FullName + "'"; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Product Delete Error", errorMessage.ToHtml(), UserMessageType.Danger); if (returnToFrontEnd) { return(RedirectToAction("ViewCategoryByName", "Catalog", new { area = "", urlName = categoryUrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } }
public ActionResult AdvancedDelete(int?id, string Tab, bool returnToManager = false) { if (!id.HasValue) { return(HttpBadRequest("NavBarItemId = null")); } StoreFront storeFront = CurrentStoreFrontOrThrow; NavBarItem navBarItem = storeFront.NavBarItems.Where(p => p.NavBarItemId == id.Value).SingleOrDefault(); if (navBarItem == null) { AddUserMessage("Menu Item not found", "Sorry, the Menu Item you are trying to Delete cannot be found. Menu Item id: [" + id.Value + "] for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Danger); return(RedirectToAction("AdvancedManager")); } NavBarItemEditAdminViewModel viewModel = new NavBarItemEditAdminViewModel(navBarItem, CurrentUserProfileOrThrow, isDeletePage: true, activeTab: Tab, returnToManager: returnToManager); return(View("AdvancedDelete", viewModel)); }
public ActionResult Create(ProductEditAdminViewModel viewModel, string createAndView) { StoreFront storeFront = CurrentStoreFrontOrThrow; bool urlIsValid = GStoreDb.ValidateProductUrlName(this, viewModel.UrlName, storeFront.StoreFrontId, storeFront.ClientId, null); if (urlIsValid && ModelState.IsValid) { try { ProcessFileUploads(viewModel, storeFront); Product product = GStoreDb.CreateProduct(viewModel, storeFront, CurrentUserProfileOrThrow); AddUserMessage("Product Created!", "Product '" + product.Name.ToHtml() + "' [" + product.ProductId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success); if (!string.IsNullOrWhiteSpace(createAndView)) { return(RedirectToAction("Details", new { id = product.ProductId, returnToFrontEnd = viewModel.ReturnToFrontEnd, tab = viewModel.ActiveTab })); } if (viewModel.ReturnToFrontEnd) { return(RedirectToAction("ViewProductByName", "Catalog", new { area = "", urlName = viewModel.UrlName })); } if (storeFront.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Products_Manager)) { return(RedirectToAction("Manager")); } return(RedirectToAction("Index", "CatalogAdmin")); } catch (Exception ex) { string errorMessage = "An error occurred while Creating Product '" + viewModel.Name + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName; if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin()) { errorMessage += " \nException.ToString(): " + ex.ToString(); } AddUserMessage("Error Creating Product!", errorMessage.ToHtmlLines(), UserMessageType.Danger); ModelState.AddModelError("Ajax", errorMessage); } } else { AddUserMessage("Create Product Error", "There was an error with your entry for new Product '" + viewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger); } if (Request.HasFiles()) { AddUserMessage("Files not uploaded", "You must correct the form values below and re-upload your files", UserMessageType.Danger); } viewModel.FillListsIfEmpty(storeFront.Client, storeFront); viewModel.IsCreatePage = true; ViewData.Add("ReturnToFrontEnd", viewModel.ReturnToFrontEnd); return(View("CreateOrEdit", viewModel)); }
public static void CreatePasswordChangedNotification(this IGstoreDb db, StoreFront storeFront, UserProfile userProfile, Uri requestUrl, string notificationBaseUrl) { if (storeFront == null) { throw new ArgumentNullException("storeFront"); } if (userProfile == null) { throw new ArgumentNullException("userProfile"); } UserProfile profile = userProfile; UserProfile accountAdmin = storeFront.CurrentConfig().AccountAdmin; Notification notification = db.Notifications.Create(); notification.StoreFront = storeFront; notification.ClientId = storeFront.ClientId; notification.From = (accountAdmin == null ? "System Administrator" : accountAdmin.FullName); notification.FromUserProfileId = (accountAdmin == null ? 0 : accountAdmin.UserProfileId); notification.ToUserProfileId = profile.UserProfileId; notification.To = profile.FullName; notification.Importance = "Normal"; notification.Subject = "FYI - Your password has been changed"; notification.UrlHost = requestUrl.Host; if (!requestUrl.IsDefaultPort) { notification.UrlHost += ":" + requestUrl.Port; } notification.BaseUrl = notificationBaseUrl; notification.Message = "FYI - Your password was changed on " + requestUrl.Host + " \n - This is just a courtesy message to let you know."; notification.Message = notification.Message.ToHtmlLines(); notification.IsPending = false; notification.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); notification.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); db.Notifications.Add(notification); db.SaveChanges(); }