public ActionResult Create(CategoryModel model, bool continueEditing, FormCollection form) { if (ModelState.IsValid) { var category = model.ToEntity(); _categoryService.InsertCategory(category); model.SeName = category.ValidateSeName(model.SeName, category.Name, true); _urlRecordService.SaveSlug(category, model.SeName, 0); UpdateLocales(category, model); var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { category.AppliedDiscounts.Add(discount); } } if (model.SelectedRuleSetIds?.Any() ?? false) { _ruleStorage.ApplyRuleSetMappings(category, model.SelectedRuleSetIds); } _categoryService.UpdateCategory(category); _categoryService.UpdateHasDiscountsApplied(category); SaveAclMappings(category, model.SelectedCustomerRoleIds); SaveStoreMappings(category, model.SelectedStoreIds); _eventPublisher.Publish(new ModelBoundEvent(model, category, form)); _customerActivityService.InsertActivity("AddNewCategory", T("ActivityLog.AddNewCategory"), category.Name); NotifySuccess(T("Admin.Catalog.Categories.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("Index")); } // If we got this far, something failed, redisplay form. PrepareTemplatesModel(model); if (model.ParentCategoryId.HasValue) { var parentCategory = _categoryService.GetCategoryTree(model.ParentCategoryId.Value, true); if (parentCategory != null) { model.ParentCategoryBreadcrumb = _categoryService.GetCategoryPath(parentCategory); } else { model.ParentCategoryId = 0; } } PrepareCategoryModel(model, null); return(View(model)); }
public ActionResult Create(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { var customerRole = model.ToEntity(); _customerService.InsertCustomerRole(customerRole); if (model.SelectedRuleSetIds?.Any() ?? false) { _ruleStorage.ApplyRuleSetMappings(customerRole, model.SelectedRuleSetIds); _customerService.UpdateCustomerRole(customerRole); } _customerActivityService.InsertActivity("AddNewCustomerRole", T("ActivityLog.AddNewCustomerRole"), customerRole.Name); NotifySuccess(T("Admin.Customers.CustomerRoles.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } return(View(model)); }
public ActionResult Create(DiscountModel model, bool continueEditing) { if (ModelState.IsValid) { var discount = model.ToEntity(); _discountService.InsertDiscount(discount); if (model.SelectedRuleSetIds?.Any() ?? false) { _ruleStorage.ApplyRuleSetMappings(discount, model.SelectedRuleSetIds); _discountService.UpdateDiscount(discount); } _customerActivityService.InsertActivity("AddNewDiscount", T("ActivityLog.AddNewDiscount"), discount.Name); NotifySuccess(T("Admin.Promotions.Discounts.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = discount.Id }) : RedirectToAction("List")); } PrepareDiscountModel(model, null); return(View(model)); }
public ActionResult CreateMethod(ShippingMethodModel model, bool continueEditing) { if (ModelState.IsValid) { var sm = model.ToEntity(); _shippingService.InsertShippingMethod(sm); if (model.SelectedRuleSetIds?.Any() ?? false) { _ruleStorage.ApplyRuleSetMappings(sm, model.SelectedRuleSetIds); _shippingService.UpdateShippingMethod(sm); } SaveStoreMappings(sm, model.SelectedStoreIds); UpdateLocales(sm, model); NotifySuccess(T("Admin.Configuration.Shipping.Methods.Added")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } return(View(model)); }
public ActionResult Edit(string systemName, bool continueEditing, PaymentMethodEditModel model, FormCollection form) { var provider = _paymentService.LoadPaymentMethodBySystemName(systemName); if (provider == null) { return(HttpNotFound()); } _pluginMediator.SetSetting(provider.Metadata, "FriendlyName", model.FriendlyName); _pluginMediator.SetSetting(provider.Metadata, "Description", model.Description); var paymentMethod = _paymentService.GetPaymentMethodBySystemName(systemName); if (paymentMethod == null) { paymentMethod = new PaymentMethod { PaymentMethodSystemName = systemName }; } paymentMethod.FullDescription = model.FullDescription; paymentMethod.RoundOrderTotalEnabled = model.RoundOrderTotalEnabled; paymentMethod.LimitedToStores = model.LimitedToStores; var updateEntity = paymentMethod.Id != 0; if (paymentMethod.Id == 0) { // In this case the update permission is sufficient. _paymentService.InsertPaymentMethod(paymentMethod); updateEntity = model.SelectedRuleSetIds?.Any() ?? false; } if (updateEntity) { // Add\remove assigned rule sets. _ruleStorage.ApplyRuleSetMappings(paymentMethod, model.SelectedRuleSetIds); _paymentService.UpdatePaymentMethod(paymentMethod); } SaveStoreMappings(paymentMethod, model.SelectedStoreIds); foreach (var localized in model.Locales) { _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "FriendlyName", localized.FriendlyName); _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "Description", localized.Description); _localizedEntityService.SaveLocalizedValue(paymentMethod, x => x.FullDescription, localized.FullDescription, localized.LanguageId); } Services.EventPublisher.Publish(new ModelBoundEvent(model, paymentMethod, form)); NotifySuccess(T("Admin.Common.DataEditSuccess")); return(continueEditing ? RedirectToAction("Edit", "Payment", new { systemName }) : RedirectToAction("Providers", "Payment")); }