public async Task <CouponDto> GetCouponAsync(string couponCode) { var coupon = await _couponRepository.GetCouponByCodeAsync(couponCode); if (coupon == null) { throw new NotFoundException("coupon not found"); } return(Mapper.Map <CouponDto>(coupon)); }
public async Task <ShoppingCartDto> ApplyCouponAsync(string couponCode) { // 1. get coupon var coupon = await _couponRepository.GetCouponByCodeAsync(couponCode); if (coupon == null) { throw new NotFoundException("coupon not found"); } // 2. get shoppingCart var user = await GetCurrentUser(); var shoppingCart = await _shoppingCartRepository.GetShoppingCartByUserIdAsync(user.Id); // 3. apply coupon & save changes shoppingCart.ApplyCoupon(coupon); await _shoppingCartRepository.SaveAsync(); // 4. return shoppingCart return(Mapper.Map <ShoppingCartDto>(shoppingCart)); }
public Task <Coupon> Handle(GetCouponByCodeQuery request, CancellationToken cancellationToken) { return(_couponRepository.GetCouponByCodeAsync(request.CouponCode, cancellationToken)); }
public async Task <CouponDto> GetActivatedCouponsByCodeAsync(string code) { return(Mapper.Map <CouponDto>(await _couponRepository.GetCouponByCodeAsync(code))); }