Exemplo n.º 1
0
 public ActionResult Bid(BidVM peanutbutter)
 {
     if (ModelState.IsValid) {
         //               bid.Bid.ItemId = id;
         _db.Bids.Add(peanutbutter.Bid);
         _db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View();
 }
Exemplo n.º 2
0
        public ActionResult Bid(int id)
        {
            var item = _db.Items.Where(i => i.Id == id).Include(i => i.Bids).FirstOrDefault();
            var bidVM = new BidVM
            {
                Bids = item.Bids.ToList(),
                Bid = new Bid
                {
                    ItemId = item.Id
                }
            };

            return View(bidVM);
        }
Exemplo n.º 3
0
        public ActionResult Bid(int id, BidVM bidVM)
        {
            // get previous max bid
            var maxBid = _db.Bids.Where(b => b.ItemId == id).Max(b => b.BidAmount);
            if (bidVM.Bid.BidAmount <= maxBid) {
                ModelState.AddModelError("Bid.BidAmount", "New bid must be greater than previous maximum bid");
            }
            // check for validation errors
            if (ModelState.IsValid) {
                bidVM.Bid.ItemId = id;
                _db.Bids.Add(bidVM.Bid);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }

            // need to repopulate previous bids
            bidVM.Bids = _db.Bids.Where(b => b.ItemId == id).ToList();
            return View(bidVM);
        }