public IActionResult CreateBid(CreateBidViewModel model, int auctionId) { var userId = _userManager.GetUserId(User); Auction auction = _context.Auctions.Where(a => a.AuctionId == auctionId) .Include(a => a.Owner) .Include(a => a.Bids) .ThenInclude(b => b.Owner) .First(); ApplicationUser user = _context.Users.Where(u => u.Id == userId) .Include(u => u.Wallet) .First(); // Validate bid greater then other bids if (auction != null) { if (model.Amount <= auction.TopBidAmount) { ModelState.AddModelError("Amount", "Amount must be greater than the current top bid"); } if (model.Amount > user.Wallet.Amount) { ModelState.AddModelError("Amount", "You can't bid more than you have"); } if (model.Amount <= auction.StartingBid) { ModelState.AddModelError("Amount", "You must bid more than the starting bid"); } if (auction.Closed) { ModelState.AddModelError("Amount", "You can only bid on auctions that have not ended"); } if (ModelState.IsValid) { auction.Bids.Add(new Bid { OwnerId = userId, CreatedById = userId, ModifiedById = userId, Amount = model.Amount } ); _context.SaveChanges(); } else { ViewBag.Auction = auction; // dont like this because of the address change but return(View("AuctionDetails", model)); } } return(RedirectToAction("Dashboard")); }
public void AddBid(CreateBidViewModel model) { using (AuctionDbContext db = new AuctionDbContext()) { Bid dbBid = new Bid { AuctionItemId = model.AuctionItemId, BidAmount = model.BidAmount, Name = model.Name }; db.Bids.Add(dbBid); db.SaveChanges(); } }
public ActionResult Bid(CreateBidViewModel model) { if (model.BidAmount < model.MinimumBid) { ModelState.AddModelError("BidAmount", "Your bid amount is not greater than or equal to the minimum"); } if (!ModelState.IsValid) { return(View(model)); } _repo.AddBid(model); return(RedirectToAction("Index")); }
public ActionResult Create(CreateBidViewModel bidViewModel) { var bid = GetBid(bidViewModel); if (!IsBidMadeForThisRegion(bid.RegionID, bid.TransportBidPlanID)) { ModelState.AddModelError("Errors", @"This Region is already registered with this Bid Plan. Please choose another Region or Plan!"); ViewBag.StatusID = new SelectList(_statusService.GetAllStatus(), "StatusID", "Name"); ViewBag.BidPlanID = bid.TransportBidPlanID; ViewBag.TransportBidPlanID = new SelectList(_transportBidPlanService.GetAllTransportBidPlan(), "TransportBidPlanID", "ShortName", bid.TransportBidPlanID); ViewBag.RegionID = new SelectList(_adminUnitService.GetRegions(), "AdminUnitID", "Name"); return(View(bidViewModel)); } if (ModelState.IsValid) { //var regions = _adminUnitService.FindBy(t => t.AdminUnitTypeID == 2); var regions = _adminUnitService.FindBy(t => t.AdminUnitID == bid.RegionID); bid.StatusID = (int)BidStatus.Open; var bidDetails = (from detail in regions select new BidDetail() { AmountForReliefProgram = (decimal)_transportBidPlanDetailService.GetRegionPlanTotal(bid.TransportBidPlanID, detail.AdminUnitID, 1), AmountForPSNPProgram = (decimal)_transportBidPlanDetailService.GetRegionPlanTotal(bid.TransportBidPlanID, detail.AdminUnitID, 2), BidDocumentPrice = 0, CPO = 0 //RegionID = bid.RegionID }).ToList(); bid.BidDetails = bidDetails; bid.RegionID = bid.RegionID; var user = (UserIdentity)System.Web.HttpContext.Current.User.Identity; bid.UserProfileId = user.Profile.UserProfileID; _bidService.AddBid(bid); return(RedirectToAction("Index")); } ViewBag.StatusID = new SelectList(_statusService.GetAllStatus(), "StatusID", "Name"); ViewBag.BidPlanID = bid.TransportBidPlanID; ViewBag.TransportBidPlanID = new SelectList(_transportBidPlanService.GetAllTransportBidPlan(), "TransportBidPlanID", "ShortName", bid.TransportBidPlanID); ViewBag.RegionID = new SelectList(_adminUnitService.GetRegions(), "AdminUnitID", "Name"); return(View(bidViewModel)); //return View("Index", _bidService.GetAllBid()); }
public CreateBidViewModel GetCreateBidViewModel(int auctionItemId) { CreateBidViewModel model = null; using (AuctionDbContext db = new AuctionDbContext()) { model = db.AuctionItems.Where(a => a.AuctionItemId == auctionItemId).Select(a => new CreateBidViewModel { AuctionItemId = a.AuctionItemId, AuctionItemName = a.Name, MinimumBid = a.MinimumBid, HighestBid = a.Bids.OrderByDescending(b => b.BidAmount).Select(b => b.BidAmount).FirstOrDefault() }).FirstOrDefault(); } return(model); }
public ActionResult Create(int id = 0) { ViewBag.RegionID = new SelectList(_adminUnitService.GetRegions(), "AdminUnitID", "Name"); var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference; var bid = new CreateBidViewModel(); bid.StartDate = DateTime.Now; bid.EndDate = DateTime.Now.AddDays(10); bid.OpeningDate = DateTime.Now.AddDays(11); var regions = _adminUnitService.FindBy(t => t.AdminUnitTypeID == 2); ViewBag.StatusID = new SelectList(_statusService.GetAllStatus(), "StatusID", "Name", bid.StatusID = 1); bid.BidNumber = _bidService.AutogenerateBidNo(); ViewBag.BidPlanID = id; ViewBag.TransportBidPlanID = new SelectList(_transportBidPlanService.GetAllTransportBidPlan(), "TransportBidPlanID", "ShortName", id); return(View(bid)); }
private Bid GetBid(CreateBidViewModel bidViewModel) { var bid = new Bid() { RegionID = bidViewModel.RegionID, StartDate = bidViewModel.StartDate, startTime = bidViewModel.StartTime, EndDate = bidViewModel.EndDate, endTime = bidViewModel.EndTime, BidNumber = bidViewModel.BidNumber, BidBondAmount = bidViewModel.BidBondAmount, OpeningDate = bidViewModel.OpeningDate, BidOpeningTime = bidViewModel.BidOpningTime, StatusID = bidViewModel.StatusID, TransportBidPlanID = bidViewModel.TransportBidPlanID }; return(bid); }
public ActionResult Bid(int id) { CreateBidViewModel model = _repo.GetCreateBidViewModel(id); return(View(model)); }