public async Task <Response> AddCouponToOrderAsync(string userId, string couponCode) { var order = await _db.OrderRepository.GetAsync(o => o.UserId == userId && !o.Status, string.Empty); string couponId = string.Empty; couponId = (await _db.CouponRepository.GetAsync(c => c.Code == couponCode, string.Empty))?.Id; if (order == null || order.Status) { return(new Response(false, "سبد خرید یافت نشد")); } if (!await _couponService.isValidAsync(couponId, userId)) { return(new Response(false, "سبد خرید یافت نشد")); } var couponOrder = new CouponOrder() { OrderId = order.Id, CouponId = couponId }; await _db.CouponOrderRepository.AddAsync(couponOrder); await _db.SaveAsync(); await UpdateOrderAsync(userId); return(new Response(true, string.Empty)); }
public Response AddCouponToOrder(string userId, string couponCode) { var order = _db.OrderRepository.Get(o => o.UserId == userId && !o.Status, string.Empty); string couponId = string.Empty; couponId = (_db.CouponRepository.Get(c => c.Code == couponCode, string.Empty))?.Id; if (order == null || order.Status) { return(new Response(false, "سبد خرید یافت نشد")); } if (!_couponService.isValid(couponId, userId)) { return(new Response(false, "سبد خرید یافت نشد")); } var couponOrder = new CouponOrder() { OrderId = order.Id, CouponId = couponId }; _db.CouponOrderRepository.Add(couponOrder); _db.Save(); UpdateOrder(userId); return(new Response(true, string.Empty)); }