public async Task <ServiceResponse <PromotionDiscountItem> > Update(Guid id, UpdatePromotionDiscountItemRequest request) { try { var result = await _baseRepository.GetById(id); if (result == null) { return(new ServiceResponse <PromotionDiscountItem>($"The requested Discount Item could not be found")); } result.ParentProductQuantity = request.ParentProductQuantity; result.FreeOfChargeQuantity = request.FreeOfChargeQuantity; result.DiscountRate = request.DiscountRate; result.EffectiveDate = request.EffectiveDate; result.EndDate = request.EndDate; result.PromotionDiscountId = request.PromotionDiscountId; result.LastUpdated = DateTime.Now; await _baseRepository.Update(id, result); return(new ServiceResponse <PromotionDiscountItem>(result)); } catch (Exception ex) { return(new ServiceResponse <PromotionDiscountItem>($"An Error Occured While Updating The Discount Item. {ex.Message}")); } }
public async Task <ActionResult> EditPromotionDiscountItem(Guid id, EditPromotionDiscountItemViewModel 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 promotionDiscountEditRequest = new UpdatePromotionDiscountItemRequest { Id = request.Id, PromotionDiscountId = request.PromotionDiscountId, ParentProductQuantity = request.ParentProductQuantity, DiscountRate = request.DiscountRate, FreeOfChargeQuantity = request.FreeOfChargeQuantity, EffectiveDate = request.EffectiveDate, EndDate = request.EndDate }; var result = await _promotionDiscountItemService.Update(id, promotionDiscountEditRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Discount Details Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(PromotionDiscountItemDetails), new { id = request.PromotionDiscountId })); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }