public async Task <ActionResult> Create(AddPromotionDiscountViewModel request) { if (!ModelState.IsValid) { Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var addPromotionRequest = new AddPromotionDiscountRequest { ProductId = request.ProductId, Description = request.Description }; var result = await _promotionDiscountService.Create(addPromotionRequest); if (!result.Success) { Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Discount Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public async Task <ServiceResponse <PromotionDiscount> > Create(AddPromotionDiscountRequest request) { try { var promotionDiscount = new PromotionDiscount { Code = GenerateCode(8), Description = request.Description, ProductId = request.ProductId }; var exist = await _baseRepository.GetByIdAndCode(promotionDiscount.Id, promotionDiscount.Code); if (exist != null) { return(new ServiceResponse <PromotionDiscount>($"A Discount With the Provided Code and or Id Already Exist")); } await _baseRepository.Create(promotionDiscount); return(new ServiceResponse <PromotionDiscount>(promotionDiscount)); } catch (Exception ex) { return(new ServiceResponse <PromotionDiscount>($"An Error Occured While Creating The Discount. {ex.Message}")); } }