Exemplo n.º 1
0
        public IActionResult ProcessBid(float amt, int itemid, int userid)
        {
            if (ActiveUser == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            User         user        = ActiveUser;
            AuctionEvent auctionInfo = _dbContext.auctions
                                       .Where(a => a.auction_id == HttpContext.Session
                                              .GetInt32("ItemId")).SingleOrDefault();

            if (amt == 0)
            {
                TempData["Error"] = "Please specify the amount.";
                return(RedirectToAction("ShowAuction"));
            }
            else if (amt <= auctionInfo.highest_bid)
            {
                TempData["Error"] = "Your bid MUST be greater than the highest bid.";
                return(RedirectToAction("ShowAuction"));
            }
            else if (amt > user.wallet_balance)
            {
                TempData["Error"] = "You don't have enough balance for the bid.";
                return(RedirectToAction("ShowAuction"));
            }
            else
            {
                auctionInfo.highest_bid = amt;
                Bid newBid = new Bid
                {
                    bidder   = user,
                    auctions = auctionInfo,
                };
                if (_dbContext.bids.Where(b => b.auction_id == auctionInfo.auction_id) == null)
                {
                    Bid theBid = _dbContext.Add(newBid).Entity;
                }
                else
                {
                    Bid theBid = _dbContext.Update(newBid).Entity;
                }
                user.wallet_balance -= amt;
                _dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }