public ActionResult AddToCart(Guid id, int quantity) { int Quantity = quantity; Auction Auction = AuctionRepo.Get(x => x.Id == id); Batch Batch = Auction.Batch; int AvailableUnits = Batch.QuantityPurchased - (Batch.QuantityAuctioned + Batch.QuantityDisposedOf + Batch.QuantitySold); if (Quantity < AvailableUnits) { Cart CurrentCart = CartRepo.Get(x => x.Auction.BatchId == Auction.BatchId && x.CustomerId == LoggedInUser.Id); if (CurrentCart != null) { CurrentCart.Quantity += Quantity; CartRepo.Update(CurrentCart); } else { CartRepo.Add(new Cart() { AuctionId = Auction.Id, Quantity = Quantity, CustomerId = LoggedInUser.Id }); } } else { return(RedirectToAction("StockUnavailable")); } return(RedirectToAction("MyCart")); }
public ActionResult ViewProduct(Guid id) { ViewProductVM Record = new ViewProductVM(); Auction Auction = AuctionRepo.Get(x => x.Id == id); var AvailabelAuctions = AuctionLogic.ViewProductsOnAuction(); var OtherAuctionsByStore = AvailabelAuctions .Where(x => x.Batch.Product.StoreId == Auction.Batch.Product.StoreId && x.Batch.Id != Auction.BatchId) .ToList(); var AuctionsWithSimilarExpiryDate = AvailabelAuctions .Where(x => x.Batch.ExpiryDate == Auction.Batch.ExpiryDate && x.Batch.Id != Auction.BatchId) .ToList(); OnAuctionVM ProductAuction = new OnAuctionVM() { Product = Auction.Batch.Product, Auction = Auction, Batch = Auction.Batch }; Record.Product = ProductAuction; Record.ProductsFromStore = OtherAuctionsByStore; Record.ProductsWithSimilarExpiryDate = AuctionsWithSimilarExpiryDate; return(View(Record)); }