public async Task <Product> CreateProduct(string name, string category, string description, double originalPrice, string producerId) { Product product = new Product { Name = name, Category = category, Description = description, OriginalPrice = originalPrice, ProducerId = producerId }; db.Products.Add(product); await db.SaveChangesAsync(); return(product); }
public async Task <DiscountScheme> CreateDiscountScheme(int minOrderQnty, double discountedPrice, DateTime?expiryDate, double deliveryCharge, int productId) { DiscountScheme discountScheme = new DiscountScheme { MinOrderQnty = minOrderQnty, DiscountedPrice = discountedPrice, ExpiryDate = expiryDate, DeliveryCharge = deliveryCharge, ProductId = productId }; db.DiscountSchemes.Add(discountScheme); await db.SaveChangesAsync(); return(discountScheme); }
public async Task OrderBidsFromCart(params int[] bidIds) { List <Bid> bids = await db.Bids .Where(bid => bidIds.Contains(bid.BidId)) .ToListAsync(); List <DiscountScheme> discountSchemes = await db.DiscountSchemes .IncludeOptimized(ds => ds.Bids) .ToListAsync(); foreach (Bid bid in bids) { //1. For now, ignore validation whether the bids will exceed the bid limit imposed by the Discount Scheme //2. update the bidStatus that it is no longer in the cart //DiscountScheme has Bid property eager loaded DiscountScheme discountScheme = discountSchemes .FirstOrDefault(ds => ds.DiscountSchemeId == bid.DiscountSchemeId); int currentNumBids = GetNumberOfPendingBidsOfScheme(discountScheme); currentNumBids += bid.Quantity; //2. update the bidStatus that it is no longer in the cart bid.IsInCart = false; db.Bids.Update(bid); await db.SaveChangesAsync(); // If the minOrderQuantity is reached, bid is successful ... if (currentNumBids >= discountScheme.MinOrderQnty) { await SetBidSuccessDateAndDeliveryCharge(discountScheme); } } }