Example #1
0
        public async Task UseCoupon(int CouponId)
        {
            var couponToUpdate = await _discountDbContext.Coupons.Where(c => c.CouponId == CouponId).FirstOrDefaultAsync();

            if (couponToUpdate == null)
            {
                throw new Exception();
            }
            couponToUpdate.AlreadyUsed = true;
            await _discountDbContext.SaveChangesAsync();
        }
        public async Task UseCoupon(Guid couponId)
        {
            var couponToUpdate =
                await _discountDbContext.Coupons.Where(x => x.CouponId == couponId).FirstOrDefaultAsync();

            if (couponToUpdate == null)
                throw new Exception();//TODO custom exception

            couponToUpdate.AlreadyUsed = true;
            await _discountDbContext.SaveChangesAsync();
        }
Example #3
0
        public async Task UseCouponAsync(Guid couponId, CancellationToken cancellationToken = default)
        {
            var couponToUpdate =
                await _discountDbContext.Coupons.Where(x => x.CouponId == couponId)
                .FirstOrDefaultAsync(cancellationToken);

            if (couponToUpdate == null)
            {
                throw new Exception($"Coupon not found by id: {couponId}");
            }

            couponToUpdate.Used();
            await _discountDbContext.SaveChangesAsync();
        }