public IActionResult UpdateBetRecord(RecordOfBets updateBet) { if (ModelState.IsValid) { RecordOfBets oldBet = _context.RecordOfBets.Find(updateBet.BetId); oldBet.EventId = updateBet.EventId; oldBet.BetType = updateBet.BetType; oldBet.EventDate = updateBet.EventDate; oldBet.AmountBet = updateBet.AmountBet; _context.Entry(oldBet).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(oldBet); _context.SaveChanges(); } // not sure of the view to send to; would prefer to be able to do this on the home page. // if we cannot i would assume this would go to a view that shows all bets return(RedirectToAction("ViewOpenBets")); }
//CREATE public IActionResult AddBet(RecordOfBets addBet) { UserData user = new UserData(); foreach (UserData userOne in _context.UserData.ToList()) { if (userOne.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value) { user = userOne; } } if (ModelState.IsValid) { //validation to see if amount bet is less than or equal to Bet Bank amount if (addBet.AmountBet <= user.BetBankBalance) { DepositsAndWithdrawls newTransaction = new DepositsAndWithdrawls(); newTransaction.AmountOfTransaction = addBet.AmountBet * -1; newTransaction.TimeOfTransaction = DateTime.Now; newTransaction.UserId = user.UserId; newTransaction.UserMadeTransAction = true; AddPayout(newTransaction, true, user); user.BetBankBalance -= addBet.AmountBet; _context.UserData.Update(user); _context.SaveChanges(); _context.RecordOfBets.Add(addBet); _context.SaveChanges(); } else { ViewBag.error = "Not enough money in account to place bet! Enter new amount."; return(View("Error")); } } // Not sure where to return fully return(RedirectToAction("ViewOpenBets")); }
public IActionResult UpdateBet(int id) { RecordOfBets bet = _context.RecordOfBets.Find(id); EventsTable betEvent = _context.EventsTable.Find(bet.EventId); //gets the points spread and use a random number gen to get winner and set score for the eventstable betEvent.EventStatus = "STATUS_FINAL"; //gets base score for both teams, used for all lines Random random = new Random(); var baseScore = random.Next(0, 35); //sportid: 2 = NFL, 4 = NBA betEvent.HomeScore = GenScore(betEvent.SportId); betEvent.AwayScore = GenScore(betEvent.SportId); _context.EventsTable.Update(betEvent); _context.SaveChanges(); //activate BetPayoutCheck(); return(RedirectToAction("PayoutCheck", "Home", new { eventId = betEvent.EventId })); }