Exemple #1
0
        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"));
        }