public async Task <ActionResult> Edit(Guid id, EditPromotionDiscountViewModel 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 promotionDiscountUpdateRequest = new UpdatePromotionDiscountRequest { Id = request.Id, ProductId = request.ProductId, Description = request.Description }; var result = await _promotionDiscountService.Update(id, promotionDiscountUpdateRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"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: PromotionDiscounts/Edit/5 public async Task <ActionResult> Edit(Guid id) { var productDiscount = new EditPromotionDiscountViewModel(); try { var result = await _promotionDiscountService.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.ProductId = result.Data.ProductId; productDiscount.Description = result.Data.Description; return(View(productDiscount)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(productDiscount)); } }