Beispiel #1
0
        public async Task <ActionResult> Auction(AuctionViewModel model)
        {
            if (model?.Auction?.AuctionID == 0)
            {
                return(RedirectToAction("Index"));
            }

            List <String> destNames = new List <String>();

            model.Auction = auctionService.GetAuctionByID(model.Auction.AuctionID);

            if (model.Auction.IsOpen())
            {
                destNames.Add(openDestName);
            }
            else
            {
                destNames.Add(closedDestName);
                model.FullNavList  = CreateAuctionNavList(destNames);
                model.LoggedInUser = await auctionService.GetCurrentUser();

                return(View(model));
            }

            model.FullNavList  = CreateAuctionNavList(destNames);
            model.LoggedInUser = await auctionService.GetCurrentUser();

            if (ModelState.IsValidField("AuctionBid.BidAmount") == false)
            {
                ModelState.AddModelError(String.Empty, "Bid amount submitted was not a number.");
                model.AuctionBid.BidAmount = 0;

                return(View(model));
            }

            if (model.Auction.IsSilent == false)
            {
                if ((model.Auction.AuctionBids.Count > 0 && (model.Auction.PublicWinningBid() + model.Auction.Increment) > model.AuctionBid.BidAmount) ||
                    (model.Auction.AuctionBids.Count == 0 && model.AuctionBid.BidAmount < model.Auction.MinimumBid))
                {
                    ModelState.AddModelError(String.Empty, "Invalid auction bid. Ensure you have enough points and that you bid enough to meet the requirements.");

                    return(View(model));
                }

                return(RedirectToAction("BidConfirmation", new { id = model.Auction.AuctionID, bid = model.AuctionBid.BidAmount }));
            }

            model.AuctionBid.BidDate = DateTime.Now;
            model.AuctionBid.AppUser = model.LoggedInUser;
            model.AuctionBid.Auction = model.Auction;

            bool success = auctionService.AddAuctionBid(model.AuctionBid, model.Auction);

            //model.AuctionBid = new AuctionBid();

            if (success == false)
            {
                ModelState.AddModelError(String.Empty, "Invalid auction bid. Ensure you have enough points and that you bid enough to meet the requirements.");
            }

            return(View(model));
        }