public ActionResult BidOnItem(int id, Bid bid) { var original = _db.Items.Find(id); if (ModelState.IsValid) { original.Bids.Add(bid); original.NumberOfBids = (from n in _db.Bids where n.Item.Id == id select n).Count()+1; _db.SaveChanges(); return RedirectToAction("Index","Items"); } var vm = new BidOnItemVM { Item = original }; return View(vm); }
public Bid Create(int value, int currentPrice, string bidderId, string winnerId, int auctionId, IList<string> receiversIds) { string winnerUsername = string.Empty; if (!string.IsNullOrEmpty(winnerId)) { winnerUsername = this.users.GetById(winnerId).UserName.ToString(); } var bid = new Bid { Value = value, CurrentPrice = currentPrice, BidderId = bidderId, WinnerId = winnerId, WinnerUsername = winnerUsername, AuctionId = auctionId, }; if (receiversIds[0] == "All") { bid.Bidders = auctions.GetById(auctionId).Bidders.ToList(); } else { foreach (var userId in receiversIds) { var receiver = this.users.GetById(userId); bid.Bidders.Add(receiver); } } this.bids.Add(bid); this.bids.Save(); return bid; }