public async Task <ActionResult> Edit(Guid id, EditProductDiscountViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (!id.Equals(request.Id)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var productDiscountUpdateRequest = new UpdateProductDiscountRequest { Id = request.Id, Name = request.Name, CatalogueId = request.CatalogueId, CategoryId = request.CategoryId, BrandId = request.BrandId, PackagingId = request.PackagingId, ProductId = request.ProductId, EffectiveDate = request.EffectiveDate, EndDate = request.EndDate }; var result = await _productDiscountService.Update(id, productDiscountUpdateRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Product Discount Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
// GET: ProductDiscount/Edit/5 public async Task <ActionResult> Edit(Guid id) { var productDiscount = new EditProductDiscountViewModel(); try { var result = await _productDiscountService.FindById(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(productDiscount)); } productDiscount.Id = result.Data.Id; productDiscount.Name = result.Data.Name; productDiscount.CatalogueId = result.Data.CatalogueId; productDiscount.CategoryId = result.Data.CategoryId; productDiscount.BrandId = result.Data.BrandId; productDiscount.PackagingId = result.Data.PackagingId; productDiscount.ProductId = result.Data.ProductId; productDiscount.EffectiveDate = result.Data.EffectiveDate; productDiscount.EndDate = result.Data.EndDate; return(View(productDiscount)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(productDiscount)); } }