public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } int nId = id ?? default(int); var promoCode = await _promoCodeRepository.GetById(nId); if (promoCode == null) { return(NotFound()); } var promoView = new PromoCodeViewModel() { Amount = promoCode.Amount, Coupon = promoCode.Coupon, DiscountPercent = promoCode.DiscountPercent, Id = promoCode.Id, UsedAmount = promoCode.UsedAmount }; return(View(promoView)); }
public ActionResult AddPromo(PromoCodeViewModel model) { ViewBag.ErrorFlag = false; if (!ModelState.IsValid) { return(View()); } try { try { PromoCode promo = new PromoCode(model.Code, model.Discount); return(RedirectToAction("ViewPromos")); } catch (UniqueKeyViolationException ex) { ViewBag.ErrorFlag = true; ModelState.AddModelError(String.Empty, ex.Message); return(View()); } } catch (Exception ex) { return(RedirectToAction("ErrorPage", "Error", ex)); } }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } try { var promoId = id ?? default(int); var promoCode = await _promoCodeRepository.GetById(promoId); if (promoCode == null) { return(NotFound()); } var promoView = new PromoCodeViewModel() { Amount = promoCode.Amount, Id = promoCode.Id, Coupon = promoCode.Coupon, DiscountPercent = promoCode.DiscountPercent, UsedAmount = promoCode.UsedAmount }; return(View(promoView)); } catch (Exception e) { return(View("Error")); } }
public async Task <SpecialOfferViewModel> GetValidShopOfferAsync(CancellationToken ct = default) { // retrieve all special offers List <SpecialOffer> specialOffers = await this._specialOfferRepository.GetAllAsync(ct); List <SpecialOffer> shopOffers = specialOffers.Where(o => o.Scope == OfferScope.Shop && o.ExpireDate > DateTime.Now).ToList(); SpecialOfferViewModel shopOffer = null; // if the count is greater than 1 then we have a problem, we only ever want to display one shop offer if (shopOffers.Count == 1) { shopOffer = SpecialOfferConverter.Convert(shopOffers.First()); // check if shop offer is a promo code if (shopOffer.Type == OfferType.PromoCode) { if (String.IsNullOrEmpty(shopOffer.PromoCodeId) == false) { PromoCodeViewModel promoViewModel = PromoCodeConverter.Convert(await this._promoCodeRepository.GetByIdAsync(shopOffer.PromoCodeId, ct)); // check if promo is valid if (promoViewModel.ExpireDate > DateTime.Now) { shopOffer.PromoCode = promoViewModel; } } } } return(shopOffer); }
public async Task <IActionResult> CheckPromoCode([FromBody] PromoCodeViewModel model) { var promoCode = await _promoCodeManager.GetPromoCodeByCodeAsync(model.Value); return(await _calcService.IsValidPromoCodeAsync(promoCode.Value) ? Ok() : NotFound()); }
public static PromoCodeViewModel Convert(PromoCode promo) { PromoCodeViewModel model = new PromoCodeViewModel(); model.Id = promo.Id; model.DiscountValue = promo.DiscountValue; model.ExpireDate = promo.ExpireDate; model.Type = promo.Type; model.Code = promo.Code; return(model); }
private async Task <CustomProductViewModel> GetCustomSackProdctAsync(CancellationToken ct = default) { CustomProduct customSack = await this._customProductRepository.GetCustomSackAsync(ct); List <MixCategory> mixCategories = await this._mixCategoryRepository.GetAllByProductIdAsync(customSack.Id); foreach (MixCategory category in mixCategories) { category.Ingredients = await this._ingredientRepository.GetAllByMixCategoryIdAsync(category.Id, ct); } customSack.MixCategories = mixCategories; CustomProductViewModel customSackView = CustomProductConverter.Convert(customSack); if (customSackView.IsOnSale == true) { List <SaleItem> sales = await this._saleItemRepository.GetByCustomProductId(customSack.Id); List <SaleItemViewModel> saleViews = new List <SaleItemViewModel>(); foreach (SaleItem sale in sales) { SaleItemViewModel saleView = SaleItemConverter.Convert(sale); // if sale item is a promo code if (sale.Type == OfferType.PromoCode) { // ensure promo code id exists on if (String.IsNullOrEmpty(sale.PromoCodeId) == false) { PromoCodeViewModel promoViewModel = PromoCodeConverter.Convert(await this._promoCodeRepository.GetByIdAsync(sale.PromoCodeId, ct)); // check if promo is valid if (promoViewModel.ExpireDate > DateTime.Now) { saleView.PromoCode = promoViewModel; saleViews.Add(saleView); } } } else { // if sale is valid if (sale.ExpireDate > DateTime.Now) { saleViews.Add(saleView); } } } customSackView.Sales = saleViews; } return(customSackView); }
public async Task <IActionResult> Create(PromoCodeViewModel promoCodeView) { if (ModelState.IsValid) { var promoCode = new PromoCode() { Amount = promoCodeView.Amount, Coupon = promoCodeView.Coupon, DiscountPercent = promoCodeView.DiscountPercent, }; await _promoCodeRepository.Create(promoCode); } return(RedirectToAction(nameof(Index))); }
public async Task <PromoCodeResponceViewModel> HandleResponsePromocode([FromBody] PromoCodeViewModel model) { if (ModelState.IsValid) { try { ApplyDiscountCommandResult PromocodeData = await _commandSender.Send <ApplyDiscountCommand, ApplyDiscountCommandResult>(new ApplyDiscountCommand { TransactionId = model.TransactionId, Promocode = model.Promocode, Channel = Channels.Feel }); return(new PromoCodeResponceViewModel { TransactionId = PromocodeData.Id, IsLimitExceeds = PromocodeData.IsLimitExceeds, CurrencyId = PromocodeData.CurrencyId, GrossTicketAmount = PromocodeData.GrossTicketAmount, DeliveryCharges = PromocodeData.DeliveryCharges, ConvenienceCharges = PromocodeData.ConvenienceCharges, ServiceCharge = PromocodeData.ServiceCharge, DiscountAmount = PromocodeData.DiscountAmount, NetTicketAmount = PromocodeData.NetTicketAmount, Success = PromocodeData.Id > 0 ? true : false, IsPaymentBypass = PromocodeData.IsPaymentBypass }); } catch (Exception e) { return(new PromoCodeResponceViewModel { TransactionId = 0, Success = false }); } } return(new PromoCodeResponceViewModel { TransactionId = 0, Success = false }); }
public async Task <IActionResult> GetTotalPrice([FromBody] PromoCodeViewModel model) { IEnumerable <ProductDto> products = new List <ProductDto>(); var cart = await _cartService.GetAsync(User.GetUserIdByClaimsPrincipal()); if (cart.ProductIds.Any()) { products = await _productManager.GetAllProductsByIdsAsync(cart.ProductIds); } var promoCodeValue = decimal.Zero; if (model is not null) { var promoCode = await _promoCodeManager.GetPromoCodeByCodeAsync(model.Value); promoCodeValue = promoCode.Value; } var totalPriceWithPromoCode = await _calcService.GetTotalPriceAsync(products, promoCodeValue); return(Json(new { totalPriceWithPromoCode, promoCodeValue })); }
public async Task <IActionResult> Edit(int id, PromoCodeViewModel promoCodeView) { if (id != promoCodeView.Id) { return(NotFound()); } try { var promocode = await _promoCodeRepository.GetById(id); promocode.Amount = promoCodeView.Amount; promocode.Coupon = promoCodeView.Coupon; promocode.DiscountPercent = promoCodeView.DiscountPercent; await _promoCodeRepository.Update(promocode); return(RedirectToAction("Index")); } catch (Exception e) { return(View("Error")); } }