Exemplo n.º 1
0
        public ActionResult Auction(long id)
        {
            AuctionContext context = new AuctionContext();
            var auction = db.Auctions.Find(id);

            return View(auction);
        }
Exemplo n.º 2
0
        public ActionResult Bid(Bid bid)
        {
            AuctionContext context = new AuctionContext();
            var auction = db.Auctions.Find(bid.AuctionId);

            if (auction == null)
            {
                ModelState.AddModelError("AuctionId", "Auction not found!");
            }
            else if (auction.CurrentPrice >= bid.Amount)
            {
                ModelState.AddModelError("Amount", "Bid amount must exceed current bid");
            }
            else
            {
                bid.Username = User.Identity.Name;
                auction.Bids.Add(bid);
                auction.CurrentPrice = bid.Amount;
                db.SaveChanges();
            }

            if (!Request.IsAjaxRequest())
                return RedirectToAction("Auction", new { id = bid.AuctionId });

            return Json(new
            {
                CurrentPrice = bid.Amount.ToString("C"),
                BidCount = auction.BidCount
            });
        }
Exemplo n.º 3
0
        public ActionResult Index(string auctionCategory, string searchString)
        {
            AuctionContext context = new AuctionContext();
            //var auctions = context.Auctions.ToList();

            var CategoryLst = new List<string>();
            var CategoryQry = from d in db.Auctions
                           select d.Category;

            CategoryLst.AddRange(CategoryQry.Distinct());
            ViewBag.auctionCategory = new SelectList(CategoryLst);

            var auctions = from m in db.Auctions
                        select m;

            if(!String.IsNullOrEmpty(searchString))
            {
                auctions = auctions.Where(s => s.Title.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(auctionCategory))
            {
                auctions = auctions.Where(x => x.Category == auctionCategory);
            }

            return View(auctions);
        }