public ActionResult Edit(BrandModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var brand = _brandService.GetBrandById(model.Id); if (brand == null) { //No product attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { brand = model.ToEntity(brand); _brandService.UpdateBrand(brand); UpdateLocales(brand, model); //activity log _customerActivityService.InsertActivity("EditBrand", _localizationService.GetResource("ActivityLog.EditBrand"), brand.Name); SuccessNotification(_localizationService.GetResource("Admin.Brand.Updated")); return(continueEditing ? RedirectToAction("Edit", brand.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public virtual async Task <Brand> UpdateBrandModel(Brand brand, BrandModel model) { string prevPictureId = brand.PictureId; brand = model.ToEntity(brand); brand.UpdatedOnUtc = DateTime.UtcNow; brand.Locales = await model.Locales.ToTranslationProperty(brand, x => x.Name, _seoSettings, _slugService, _languageService); //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToBrands, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { //new discount if (brand.AppliedDiscounts.Count(d => d == discount.Id) == 0) { brand.AppliedDiscounts.Add(discount.Id); } } else { //remove discount if (brand.AppliedDiscounts.Count(d => d == discount.Id) > 0) { brand.AppliedDiscounts.Remove(discount.Id); } } } model.SeName = await brand.ValidateSeName(model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService); brand.SeName = model.SeName; await _brandService.UpdateBrand(brand); //search engine name await _slugService.SaveSlug(brand, model.SeName, ""); //delete an old picture (if deleted or updated) if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != brand.PictureId) { var prevPicture = await _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { await _pictureService.DeletePicture(prevPicture); } } //update picture seo file name await _pictureService.UpdatePictureSeoNames(brand.PictureId, brand.Name); //activity log await _customerActivityService.InsertActivity("EditBrand", brand.Id, _translationService.GetResource("ActivityLog.EditBrand"), brand.Name); return(brand); }
public virtual ActionResult Edit(BrandModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageBrands)) { return(AccessDeniedView()); } var brand = _brandService.GetBrandById(model.Id); if (brand == null || brand.Deleted) { //No manufacturer found with the specified id return(RedirectToAction("List")); } if (!ModelState.IsValid) { return(View(model)); } int prevPictureId = brand.PictureId; brand = model.ToEntity(brand); brand.UpdatedOnUtc = DateTime.UtcNow; _brandService.UpdateBrand(brand); //delete an old picture (if deleted or updated) if (prevPictureId > 0 && prevPictureId != brand.PictureId) { var prevPicture = _pictureService.GetPictureById(prevPictureId); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(brand); //activity log _customerActivityService.InsertActivity("EditBrand", _localizationService.GetResource("ActivityLog.EditBrand"), brand.Name); SuccessNotification(_localizationService.GetResource("Moveleiros.Admin.Catalog.Brands.Updated")); if (continueEditing) { //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = brand.Id })); } return(RedirectToAction("List")); }
public virtual ActionResult Create(BrandModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageBrands)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(View(model)); } var brand = model.ToEntity(); brand.CreatedOnUtc = DateTime.UtcNow; brand.UpdatedOnUtc = DateTime.UtcNow; _brandService.InsertBrand(brand); //update picture seo file name UpdatePictureSeoNames(brand); //activity log _customerActivityService.InsertActivity("AddNewBrand", _localizationService.GetResource("ActivityLog.AddNewBrand"), brand.Name); SuccessNotification(_localizationService.GetResource("Moveleiros.Admin.Catalog.Brands.Added")); if (continueEditing) { //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = brand.Id })); } return(RedirectToAction("List")); }
public virtual async Task <Brand> InsertBrandModel(BrandModel model) { var brand = model.ToEntity(); brand.CreatedOnUtc = DateTime.UtcNow; brand.UpdatedOnUtc = DateTime.UtcNow; //discounts var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToBrands, showHidden : true); foreach (var discount in allDiscounts) { if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id)) { brand.AppliedDiscounts.Add(discount.Id); } } await _brandService.InsertBrand(brand); //search engine name brand.Locales = await model.Locales.ToTranslationProperty(brand, x => x.Name, _seoSettings, _slugService, _languageService); model.SeName = await brand.ValidateSeName(model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService); brand.SeName = model.SeName; await _brandService.UpdateBrand(brand); await _slugService.SaveSlug(brand, model.SeName, ""); //update picture seo file name await _pictureService.UpdatePictureSeoNames(brand.PictureId, brand.Name); //activity log await _customerActivityService.InsertActivity("AddNewBrand", brand.Id, _translationService.GetResource("ActivityLog.AddNewBrand"), brand.Name); return(brand); }
public ActionResult Create(BrandModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var brand = model.ToEntity(); brand.CreatedOnUtc = DateTime.UtcNow; _brandService.InsertBrand(brand); UpdateLocales(brand, model); //activity log _customerActivityService.InsertActivity("AddNewBrand", _localizationService.GetResource("ActivityLog.AddNewBrand"), brand.Name); SuccessNotification(_localizationService.GetResource("Admin.Brand.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = brand.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }