public IActionResult ProcessRegister(Users inp) { List <CurrentUser> ret = HttpContext.Session.GetObjectFromJson <List <CurrentUser> >("curr"); if (ret == null) { return(RedirectToAction("")); } ViewBag.CurrentUser = ret[0]; if (ModelState.IsValid) { PasswordHasher <Users> Hasher = new PasswordHasher <Users>(); inp.password = Hasher.HashPassword(inp, inp.password); inp.wallet = 1000; _context.Add(inp); _context.SaveChanges(); Users check = _context.users.SingleOrDefault(x => x.email == inp.email); CurrentUser newcurr = new CurrentUser(); newcurr.id = check.id; newcurr.name = check.first_name + " " + check.last_name; newcurr.wallet = check.wallet; List <object> temp = new List <object>(); temp.Add(newcurr); HttpContext.Session.SetObjectAsJson("curr", temp); return(RedirectToAction("Dashboard", "Home")); } else { return(View("Register")); } }
/////////////////////////////////////////////////////////////////////////////////// // public IActionResult CheckFinishedAuctions() { List <Auctions> allAuctions = _context.auctions.Include(a => a.seller).Include(a => a.bidders).ThenInclude(b => b.bidder).ToList(); List <CurrentUser> ret = HttpContext.Session.GetObjectFromJson <List <CurrentUser> >("curr"); foreach (var auct in allAuctions) { var today = DateTime.Now; TimeSpan remaining = auct.endDate.Subtract(today); if (remaining.TotalSeconds <= 0) { if (auct.bidders.Count == 0) { _context.auctions.Remove(auct); _context.SaveChanges(); } else { Bidders highestbidder = _context.bidders.Where(b => b.auctionid == auct.id).Include(b => b.bidder).OrderByDescending(b => b.bidamount).First(); auct.seller.wallet += auct.bid; if (ret[0].id == auct.seller.id) { ret[0].wallet += auct.bid; HttpContext.Session.SetObjectAsJson("curr", ret); } highestbidder.bidder.wallet -= auct.bid; if (ret[0].id == highestbidder.id) { ret[0].wallet -= auct.bid; HttpContext.Session.SetObjectAsJson("curr", ret); } foreach (var bids in auct.bidders) { _context.bidders.Remove(bids); } _context.auctions.Remove(auct); _context.SaveChanges(); } } } return(RedirectToAction("")); }