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()); } }
public async Task <ServiceResponse <PromotionDiscount> > Update(Guid id, UpdatePromotionDiscountRequest request) { try { var result = await _baseRepository.GetById(id); if (result == null) { return(new ServiceResponse <PromotionDiscount>($"The requested Discount could not be found")); } result.ProductId = request.ProductId; result.Description = request.Description; result.LastUpdated = DateTime.Now; await _baseRepository.Update(id, result); return(new ServiceResponse <PromotionDiscount>(result)); } catch (Exception ex) { return(new ServiceResponse <PromotionDiscount>($"An Error Occured While Updating The Discount. {ex.Message}")); } }