public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { //No manufacturer found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return(View(model)); }
public virtual Manufacturer InsertManufacturerModel(ManufacturerModel model) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { manufacturer.AppliedDiscounts.Add(discount.Id); } } _manufacturerService.InsertManufacturer(manufacturer); //search engine name manufacturer.Locales = model.Locales.ToLocalizedProperty(manufacturer, x => x.Name, _urlRecordService); model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); manufacturer.SeName = model.SeName; _manufacturerService.UpdateManufacturer(manufacturer); _urlRecordService.SaveSlug(manufacturer, model.SeName, ""); //update picture seo file name _pictureService.UpdatePictureSeoNames(manufacturer.PictureId, manufacturer.Name); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); return(manufacturer); }
public IActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; manufacturer.Stores = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>(); manufacturer.CustomerRoles = model.SelectedCustomerRoleIds != null?model.SelectedCustomerRoleIds.ToList() : new List <string>(); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { manufacturer.AppliedDiscounts.Add(discount.Id); } } _manufacturerService.InsertManufacturer(manufacturer); //search engine name manufacturer.Locales = UpdateLocales(manufacturer, model); model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); manufacturer.SeName = model.SeName; _manufacturerService.UpdateManufacturer(manufacturer); _urlRecordService.SaveSlug(manufacturer, model.SeName, ""); //update "HasDiscountsApplied" property //_manufacturerService.UpdateHasDiscountsApplied(manufacturer); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, null, true); //ACL PrepareAclModel(model, null, true); //Stores PrepareStoresMappingModel(model, null, true); return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing, FormCollection form) { var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); UpdateLocales(manufacturer, model); var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, null, true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { if (manufacturer.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() == 0) { manufacturer.AppliedDiscounts.Add(discount); } } else { if (manufacturer.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() > 0) { manufacturer.AppliedDiscounts.Remove(discount); } } } manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); Services.EventPublisher.Publish(new ModelBoundEvent(model, manufacturer, form)); UpdatePictureSeoNames(manufacturer); SaveStoreMappings(manufacturer, model.SelectedStoreIds); _customerActivityService.InsertActivity("EditManufacturer", T("ActivityLog.EditManufacturer"), manufacturer.Name); NotifySuccess(T("Admin.Catalog.Manufacturers.Updated")); return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List")); } // If we got this far, something failed, redisplay form. PrepareTemplatesModel(model); PrepareManufacturerModel(model, manufacturer); return(View(model)); }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity(); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); _manufacturerService.InsertManufacturer(manufacturer); // search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); // locales UpdateLocales(manufacturer, model); // discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, null, true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { manufacturer.AppliedDiscounts.Add(discount); } } var hasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; if (hasDiscountsApplied) { manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; _manufacturerService.UpdateManufacturer(manufacturer); } // update picture seo file name UpdatePictureSeoNames(manufacturer); // Stores _storeMappingService.SaveStoreMappings <Manufacturer>(manufacturer, model.SelectedStoreIds); // activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); PrepareManufacturerModel(model, null, true); return(View(model)); }
public virtual async Task <Manufacturer> UpdateManufacturerModel(Manufacturer manufacturer, ManufacturerModel model) { string prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; manufacturer.Locales = await model.Locales.ToLocalizedProperty(manufacturer, x => x.Name, _seoSettings, _urlRecordService, _languageService); //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) == 0) { manufacturer.AppliedDiscounts.Add(discount.Id); } } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) > 0) { manufacturer.AppliedDiscounts.Remove(discount.Id); } } } model.SeName = await manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true, _seoSettings, _urlRecordService, _languageService); manufacturer.SeName = model.SeName; await _manufacturerService.UpdateManufacturer(manufacturer); //search engine name await _urlRecordService.SaveSlug(manufacturer, model.SeName, ""); //delete an old picture (if deleted or updated) if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != manufacturer.PictureId) { var prevPicture = await _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { await _pictureService.DeletePicture(prevPicture); } } //update picture seo file name await _pictureService.UpdatePictureSeoNames(manufacturer.PictureId, manufacturer.Name); //activity log await _customerActivityService.InsertActivity("EditManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); return(manufacturer); }
public virtual IActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity <Manufacturer>(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //search engine name model.SeName = _urlRecordService.ValidateSeName(manufacturer, model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); _manufacturerService.UpdateManufacturer(manufacturer); //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL (customer roles) SaveManufacturerAcl(manufacturer, model); //stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", string.Format(_localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name), manufacturer); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); if (!continueEditing) { return(RedirectToAction("List")); } //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = _manufacturerModelFactory.PrepareManufacturerModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //Stores _storeMappingService.SaveStoreMappings <Manufacturer>(manufacturer, model.SelectedStoreIds); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); PrepareManufacturerModel(model, manufacturer, true); return(View(model)); }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (ModelState.IsValid) { var manufacturer = model.ToEntity(); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.MediaFileId); _manufacturerService.InsertManufacturer(manufacturer); model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); UpdateLocales(manufacturer, model); var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, null, true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { manufacturer.AppliedDiscounts.Add(discount); } } var hasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; if (hasDiscountsApplied) { manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; _manufacturerService.UpdateManufacturer(manufacturer); } UpdatePictureSeoNames(manufacturer); SaveAclMappings(manufacturer, model.SelectedCustomerRoleIds); SaveStoreMappings(manufacturer, model.SelectedStoreIds); _customerActivityService.InsertActivity("AddNewManufacturer", T("ActivityLog.AddNewManufacturer"), manufacturer.Name); NotifySuccess(T("Admin.Catalog.Manufacturers.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List")); } // If we got this far, something failed, redisplay form. PrepareTemplatesModel(model); PrepareManufacturerModel(model, null); return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { throw new ArgumentException("No manufacturer found with the specified id"); } //decode description model.Description = HttpUtility.HtmlDecode(model.Description); foreach (var localized in model.Locales) { localized.Description = HttpUtility.HtmlDecode(localized.Description); } if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) return RedirectToAction("List"); if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //Stores _storeMappingService.SaveStoreMappings<Manufacturer>(manufacturer, model.SelectedStoreIds); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); PrepareManufacturerModel(model, manufacturer, true); return View(model); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return RedirectToAction("Edit", manufacturer.Id); } else { return RedirectToAction("List"); } } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return View(model); }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL (customer roles) SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, null, true); //Stores PrepareStoresMappingModel(model, null, true); return View(model); }
public virtual IActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } //try to get a manufacturer with the specified id var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { var prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = _urlRecordService.ValidateSeName(manufacturer, model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.DiscountManufacturerMappings.Count(mapping => mapping.DiscountId == discount.Id) == 0) { manufacturer.DiscountManufacturerMappings.Add(new DiscountManufacturerMapping { Discount = discount }); } } else { //remove discount if (manufacturer.DiscountManufacturerMappings.Count(mapping => mapping.DiscountId == discount.Id) > 0) { manufacturer.DiscountManufacturerMappings .Remove(manufacturer.DiscountManufacturerMappings.FirstOrDefault(mapping => mapping.DiscountId == discount.Id)); } } } _manufacturerService.UpdateManufacturer(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", string.Format(_localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name), manufacturer); _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = _manufacturerModelFactory.PrepareManufacturerModel(model, manufacturer, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); return View(model); }
public virtual async Task <IActionResult> Edit(ManufacturerModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } //try to get a manufacturer with the specified id var manufacturer = await _manufacturerService.GetManufacturerByIdAsync(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { var prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; await _manufacturerService.UpdateManufacturerAsync(manufacturer); //search engine name model.SeName = await _urlRecordService.ValidateSeNameAsync(manufacturer, model.SeName, manufacturer.Name, true); await _urlRecordService.SaveSlugAsync(manufacturer, model.SeName, 0); //locales await UpdateLocalesAsync(manufacturer, model); //discounts var allDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToManufacturers, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (await _manufacturerService.GetDiscountAppliedToManufacturerAsync(manufacturer.Id, discount.Id) is null) { await _manufacturerService.InsertDiscountManufacturerMappingAsync(new DiscountManufacturerMapping { EntityId = manufacturer.Id, DiscountId = discount.Id }); } } else { //remove discount if (await _manufacturerService.GetDiscountAppliedToManufacturerAsync(manufacturer.Id, discount.Id) is DiscountManufacturerMapping discountManufacturerMapping) { await _manufacturerService.DeleteDiscountManufacturerMappingAsync(discountManufacturerMapping); } } } await _manufacturerService.UpdateManufacturerAsync(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = await _pictureService.GetPictureByIdAsync(prevPictureId); if (prevPicture != null) { await _pictureService.DeletePictureAsync(prevPicture); } } //update picture seo file name await UpdatePictureSeoNamesAsync(manufacturer); //ACL await SaveManufacturerAclAsync(manufacturer, model); //stores await SaveStoreMappingsAsync(manufacturer, model); //activity log await _customerActivityService.InsertActivityAsync("EditManufacturer", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditManufacturer"), manufacturer.Name), manufacturer); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Catalog.Manufacturers.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = await _manufacturerModelFactory.PrepareManufacturerModelAsync(model, manufacturer, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual async Task <IActionResult> Create(ManufacturerModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var manufacturer = model.ToEntity <Manufacturer>(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; await _manufacturerService.InsertManufacturerAsync(manufacturer); //search engine name model.SeName = await _urlRecordService.ValidateSeNameAsync(manufacturer, model.SeName, manufacturer.Name, true); await _urlRecordService.SaveSlugAsync(manufacturer, model.SeName, 0); //locales await UpdateLocalesAsync(manufacturer, model); //discounts var allDiscounts = await _discountService.GetAllDiscountsAsync(DiscountType.AssignedToManufacturers, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //manufacturer.AppliedDiscounts.Add(discount); await _manufacturerService.InsertDiscountManufacturerMappingAsync(new DiscountManufacturerMapping { EntityId = manufacturer.Id, DiscountId = discount.Id }); } } await _manufacturerService.UpdateManufacturerAsync(manufacturer); //update picture seo file name await UpdatePictureSeoNamesAsync(manufacturer); //ACL (customer roles) await SaveManufacturerAclAsync(manufacturer, model); //stores await SaveStoreMappingsAsync(manufacturer, model); //activity log await _customerActivityService.InsertActivityAsync("AddNewManufacturer", string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewManufacturer"), manufacturer.Name), manufacturer); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Catalog.Manufacturers.Added")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = manufacturer.Id })); } //prepare model model = await _manufacturerModelFactory.PrepareManufacturerModelAsync(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) return AccessDeniedView(); //decode description model.Description = HttpUtility.HtmlDecode(model.Description); foreach (var localized in model.Locales) localized.Description = HttpUtility.HtmlDecode(localized.Description); if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.InsertManufacturer(manufacturer); //locales UpdateLocales(manufacturer, model); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); return View(model); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) //No manufacturer found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { int prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //locales UpdateLocales(manufacturer, model); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0) manufacturer.AppliedDiscounts.Add(discount); } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0) manufacturer.AppliedDiscounts.Remove(discount); } } _manufacturerService.UpdateManufacturer(manufacturer); //update "HasDiscountsApplied" property _manufacturerService.UpdateHasDiscountsApplied(manufacturer); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) _pictureService.DeletePicture(prevPicture); } //update picture seo file name UpdatePictureSeoNames(manufacturer); //ACL SaveManufacturerAcl(manufacturer, model); //Stores SaveStoreMappings(manufacturer, model); //activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return RedirectToAction("Edit", new {id = manufacturer.Id}); } return RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, manufacturer, true); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return View(model); }
public ActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null || manufacturer.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { manufacturer = model.ToEntity(manufacturer); MediaHelper.UpdatePictureTransientStateFor(manufacturer, m => m.PictureId); ////TBD: is it really necessary here already? //manufacturer.UpdatedOnUtc = DateTime.UtcNow; //_manufacturerService.UpdateManufacturer(manufacturer); // search engine name model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); // locales UpdateLocales(manufacturer, model); // discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, null, true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { if (manufacturer.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() == 0) { manufacturer.AppliedDiscounts.Add(discount); } } else { if (manufacturer.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() > 0) { manufacturer.AppliedDiscounts.Remove(discount); } } } manufacturer.HasDiscountsApplied = manufacturer.AppliedDiscounts.Count > 0; // Commit now _manufacturerService.UpdateManufacturer(manufacturer); // update picture seo file name UpdatePictureSeoNames(manufacturer); // Stores _storeMappingService.SaveStoreMappings <Manufacturer>(manufacturer, model.SelectedStoreIds); // activity log _customerActivityService.InsertActivity("EditManufacturer", _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); NotifySuccess(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); return(continueEditing ? RedirectToAction("Edit", manufacturer.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); PrepareManufacturerModel(model, manufacturer, true); return(View(model)); }
public ActionResult Create(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) return AccessDeniedView(); if (ModelState.IsValid) { var manufacturer = model.ToEntity(); manufacturer.CreatedOnUtc = DateTime.UtcNow; manufacturer.UpdatedOnUtc = DateTime.UtcNow; manufacturer.Stores = model.SelectedStoreIds != null ? model.SelectedStoreIds.ToList() : new List<int>(); manufacturer.CustomerRoles = model.SelectedCustomerRoleIds != null ? model.SelectedCustomerRoleIds.ToList() : new List<int>(); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) manufacturer.AppliedDiscounts.Add(discount); } _manufacturerService.InsertManufacturer(manufacturer); //search engine name manufacturer.Locales = UpdateLocales(manufacturer, model); model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); manufacturer.SeName = model.SeName; _manufacturerService.UpdateManufacturer(manufacturer); _urlRecordService.SaveSlug(manufacturer, model.SeName, 0); //update "HasDiscountsApplied" property //_manufacturerService.UpdateHasDiscountsApplied(manufacturer); //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("AddNewManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.AddNewManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Added")); return continueEditing ? RedirectToAction("Edit", new { id = manufacturer.Id }) : RedirectToAction("List"); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, null, true); //ACL PrepareAclModel(model, null, true); //Stores PrepareStoresMappingModel(model, null, true); return View(model); }
public IActionResult Edit(ManufacturerModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedView()); } var manufacturer = _manufacturerService.GetManufacturerById(model.Id); if (manufacturer == null) { //No manufacturer found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { string prevPictureId = manufacturer.PictureId; manufacturer = model.ToEntity(manufacturer); manufacturer.UpdatedOnUtc = DateTime.UtcNow; manufacturer.Locales = UpdateLocales(manufacturer, model); manufacturer.Stores = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>(); manufacturer.CustomerRoles = model.SelectedCustomerRoleIds != null?model.SelectedCustomerRoleIds.ToList() : new List <string>(); //discounts var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToManufacturers, showHidden: true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) == 0) { manufacturer.AppliedDiscounts.Add(discount.Id); } } else { //remove discount if (manufacturer.AppliedDiscounts.Count(d => d == discount.Id) > 0) { manufacturer.AppliedDiscounts.Remove(discount.Id); } } } model.SeName = manufacturer.ValidateSeName(model.SeName, manufacturer.Name, true); manufacturer.SeName = model.SeName; _manufacturerService.UpdateManufacturer(manufacturer); //search engine name _urlRecordService.SaveSlug(manufacturer, model.SeName, ""); //update "HasDiscountsApplied" property //_manufacturerService.UpdateHasDiscountsApplied(manufacturer); //delete an old picture (if deleted or updated) if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != manufacturer.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(manufacturer); //activity log _customerActivityService.InsertActivity("EditManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.EditManufacturer"), manufacturer.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Manufacturers.Updated")); if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = manufacturer.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form //templates PrepareTemplatesModel(model); //discounts PrepareDiscountModel(model, manufacturer, true); //ACL PrepareAclModel(model, manufacturer, true); //Stores PrepareStoresMappingModel(model, manufacturer, true); return(View(model)); }