public virtual IActionResult PredefinedProductAttributeValueEditPopup(PredefinedProductAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } //try to get a predefined product attribute value with the specified id var productAttributeValue = _productAttributeService.GetPredefinedProductAttributeValueById(model.Id) ?? throw new ArgumentException("No predefined product attribute value found with the specified id"); //try to get a product attribute with the specified id var productAttribute = _productAttributeService.GetProductAttributeById(productAttributeValue.ProductAttributeId) ?? throw new ArgumentException("No product attribute found with the specified id"); if (ModelState.IsValid) { productAttributeValue = model.ToEntity(productAttributeValue); _productAttributeService.UpdatePredefinedProductAttributeValue(productAttributeValue); UpdateLocales(productAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _productAttributeModelFactory.PreparePredefinedProductAttributeValueModel(model, productAttribute, productAttributeValue, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } //try to get a product attribute with the specified id var productAttribute = await _productAttributeService.GetProductAttributeByIdAsync(model.ProductAttributeId) ?? throw new ArgumentException("No product attribute found with the specified id"); if (ModelState.IsValid) { //fill entity from model var ppav = model.ToEntity <PredefinedProductAttributeValue>(); await _productAttributeService.InsertPredefinedProductAttributeValueAsync(ppav); await UpdateLocalesAsync(ppav, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = await _productAttributeModelFactory.PreparePredefinedProductAttributeValueModelAsync(model, productAttribute, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public IActionResult PredefinedProductAttributeValueEditPopup(PredefinedProductAttributeValueModel model) { var productAttribute = _productAttributeService.GetProductAttributeById(model.ProductAttributeId); var ppav = productAttribute.PredefinedProductAttributeValues.Where(x => x.Id == model.Id).FirstOrDefault(); if (ppav == null) { throw new ArgumentException("No product attribute value found with the specified id"); } if (ModelState.IsValid) { ppav = model.ToEntity(ppav); _productAttributeService.UpdateProductAttribute(productAttribute); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> PredefinedProductAttributeValueCreatePopup(PredefinedProductAttributeValueModel model) { var productAttribute = await _productAttributeService.GetProductAttributeById(model.ProductAttributeId); if (productAttribute == null) { throw new ArgumentException("No product attribute found with the specified id"); } if (ModelState.IsValid) { var ppav = model.ToEntity(); productAttribute.PredefinedProductAttributeValues.Add(ppav); await _productAttributeService.UpdateProductAttribute(productAttribute); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }