public ActionResult RaceResult(DbView signUpFormData) { DbView dbView = CreateDbViewFrom(signUpFormData); // Clears previous form data inputs for next signup ModelState.Clear(); return View("SignupForm", dbView); }
public Player CreateNewPlayer(DbView signUpFormData) { // Get the new player fromt he sign up form data Player newPlayer = signUpFormData.SignUpPlayer; // Assign random horses to the new player newPlayer.Horses = AssignHorses(newPlayer.NoHorses); return newPlayer; }
// // GET: /SignupForm/ // // This is loads initial database info for the user public ActionResult SignupForm() { List<Player> dbPlayers = db.Players.ToList(); List<Horse> dbHorses = db.Horses.ToList(); List<Horse> availableHorses = dbm.GetAvailableHorses(); Status sweepstakeStatus = dbm.GetSweepstakeStatus(); DbView dbView = new DbView { AllHorses = availableHorses, AllPlayers = dbPlayers, SweepstakeStatus = sweepstakeStatus }; return View(dbView); }
// // GET: /RunRace/ public ActionResult RunRace() { // Get all horses and players from db List<Horse> dbHorses = db.Horses.ToList(); List<Player> dbPlayers = db.Players.ToList(); // Get all available horses List<Horse> availableHorses = dbm.GetAvailableHorses(); // Get the latest sweepstake status Status sweepstakeStatus = dbm.GetSweepstakeStatus(); // Create list of horses being bet on List<Horse> horsesBetOn = new List<Horse>(); // Loop through the sweepstake betting players and add thier horses to the list foreach (var player in sweepstakeStatus.BettingPlayers) horsesBetOn.AddRange(player.Horses); // Create a new list ordered by the finishing place List<Horse> winningHorses = horsesBetOn.OrderBy(h => h.FinishingPlace).ToList(); // Allocate winnings winningHorses[0].player.Winnings += (int)(sweepstakeStatus.BettingPool * 0.5); // 50% of pool winningHorses[1].player.Winnings += (int)(sweepstakeStatus.BettingPool * 0.25); // 25% of pool winningHorses[2].player.Winnings += (int)(sweepstakeStatus.BettingPool * 0.15); // 15% of pool winningHorses[winningHorses.Count - 1].player.Winnings += (int)(sweepstakeStatus.BettingPool * 0.10); // 10% of pool // Get new dbview ready DbView dbView = new DbView { AllHorses = availableHorses, AllPlayers = dbPlayers, SweepstakeStatus = sweepstakeStatus, WinningHorses = winningHorses }; // Add view to tempData for when page redirects TempData["raceResults"] = dbView; return RedirectToAction("RaceResult", "Home"); }
public ActionResult SignupForm(DbView signUpFormData) { DbView dbView = CreateDbViewFrom(signUpFormData); return View("SignupForm", dbView); }
// // ProcessHttpPost // // Used for SignupForm POST and RaceResult POST // // This processes the post data from the form and returns a DbView for the view private DbView CreateDbViewFrom(DbView signUpFormData) { // Get the new player fromt he sign up form data Player newPlayer = dbm.CreateNewPlayer(signUpFormData); // Clears previous form data inputs for next signup ModelState.Clear(); // When creating the view the order is IMPORTANT DbView dbView = new DbView(); // 1. Can add new player to the database dbView.PlayerExists = dbm.AddPlayer(newPlayer, ModelState.IsValid); // 2. Get available horses dbView.AllHorses = dbm.GetAvailableHorses(); // 3. Create sweepstakes information for the webpage dbView.SweepstakeStatus = dbm.GetSweepstakeStatus(); // 4. Get latest list of all players in the db dbView.AllPlayers = db.Players.ToList(); // 5. Clears the signup player field in the DbView dbView.SignUpPlayer = new Player(); // Returns a new DbView return dbView; }