示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
 public Task <Coupon> Handle(GetCouponByCodeQuery request, CancellationToken cancellationToken)
 {
     return(_couponRepository.GetCouponByCodeAsync(request.CouponCode, cancellationToken));
 }
示例#4
0
 public async Task <CouponDto> GetActivatedCouponsByCodeAsync(string code)
 {
     return(Mapper.Map <CouponDto>(await _couponRepository.GetCouponByCodeAsync(code)));
 }