// GET: RoundMatchups public async Task <IActionResult> Index() { int currentRound = RoundMatchupActions.GetLastRoundNo(_context); List <RoundMatchup> roundMatchups = await _context.RoundMatchups.Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Where(r => r.RoundNo == currentRound).OrderByDescending(r => r.PlayerOne.BattleScore).ToListAsync(); return(View(roundMatchups)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,RoundNo,PlayerOneBattleScore,PlayerTwoBattleScore,PlayerOneSportsmanshipPoints,PlayerTwoSportsmanshipPoints,Table")] RoundMatchup roundMatchups) { if (id != roundMatchups.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(roundMatchups); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchups.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(roundMatchups)); }
//Reset the matchups public ActionResult ResetRoundMatchups() { int roundNo = RoundMatchupActions.GetLastRoundNo(_context); Boolean pairRoundMatchup = false; foreach (RoundMatchup roundMatchup in _context.RoundMatchups.Include(r => r.PlayerTwo).Where(r => r.RoundNo == roundNo).ToList()) { if (roundMatchup is PairRoundMatchup && roundMatchup.PlayerTwo != null) { pairRoundMatchup = true; } _context.Remove(roundMatchup); } _context.SaveChanges(); if (pairRoundMatchup == true) { if (RoundMatchupActions.GenerateNextPairRound(_context) == false) { TempData["Errors"] = "There are no unique matchups left, manual selection will be required (Random Matchups have been allocated where opponents from last round are teammates)"; } } else { if (RoundMatchupActions.GenerateNextRound(_context) == false) { TempData["Errors"] = "There are no unique matchups left, manual selection will be required (Matchups are generated based on most evenly skilled players according to BattleScore, with no regard for previous opponents)"; } } return(RedirectToAction(nameof(Index), "Admin")); }
public async Task <IActionResult> RoundMatchupEdit(int id, [Bind("Id, RoundNo, PlayerOneId, PlayerTwoId, PlayerOneBattleScore, PlayerTwoBattleScore, PlayerOneSportsmanshipScore, PlayerTwoSportsmanshipScore, Table")] RoundMatchupEditViewModel roundMatchupvm) { if (id != roundMatchupvm.Id) { return(NotFound()); } //Check if a player is versing themself or on a team with themself if (roundMatchupvm.PlayerOneId == roundMatchupvm.PlayerTwoId) { TempData["Errors"] = "A player cannot verse themself or be on a team with themself"; roundMatchupvm.Players = _context.Players.ToList(); return(View(roundMatchupvm)); } var playerOne = await _context.Players.SingleOrDefaultAsync(p => p.Id == roundMatchupvm.PlayerOneId); var playerTwo = await _context.Players.SingleOrDefaultAsync(p => p.Id == roundMatchupvm.PlayerTwoId); var roundMatchup = new RoundMatchup() { Id = roundMatchupvm.Id, RoundNo = roundMatchupvm.RoundNo, PlayerOne = playerOne, PlayerOneBattleScore = roundMatchupvm.PlayerOneBattleScore, PlayerOneSportsmanshipScore = roundMatchupvm.PlayerOneSportsmanshipScore, PlayerTwo = playerTwo, PlayerTwoBattleScore = roundMatchupvm.PlayerTwoBattleScore, PlayerTwoSportsmanshipScore = roundMatchupvm.PlayerTwoSportsmanshipScore, Table = roundMatchupvm.Table }; if (ModelState.IsValid) { try { _context.Update(roundMatchup); await _context.SaveChangesAsync(); PlayerActions.SetPlayerScores((int)roundMatchupvm.PlayerOneId, _context); PlayerActions.SetPlayerScores((int)roundMatchupvm.PlayerTwoId, _context); } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchup.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(AllRounds))); } roundMatchupvm.Players = _context.Players.ToList(); return(View(roundMatchupvm)); }
// GET: RoundMatchups public async Task <IActionResult> Index() { int lastRoundNo = RoundMatchupActions.GetLastRoundNo(_context); //Get all rounds as list from database and then filter using the where clause (potentially inefficient but no time to sort out lazy loading issue) var roundMatchups = _context.RoundMatchups.Where(r => !(r is PairRoundMatchup)).Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).ToList(); var pairRoundMatchups = _context.PairRoundMatchups.Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Include(r => r.PlayerThree).Include(r => r.PlayerFour).ToList(); return(View(roundMatchups.Union(pairRoundMatchups))); }
// GET: RoundMatchups Results public ActionResult Index() { int lastRoundNo = RoundMatchupActions.GetLastRoundNo(_context); var roundMatchups = _context.RoundMatchups.Where(r => !(r is PairRoundMatchup)).Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).ToList(); var pairRoundMatchups = _context.PairRoundMatchups.Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Include(r => r.PlayerThree).Include(r => r.PlayerFour).ToList(); return(View(roundMatchups.Union(pairRoundMatchups).OrderBy(r => r.RoundNo))); }
public async Task <IActionResult> PairRoundMatchupEdit(int id, [Bind("Id,RoundNo,PlayerOneId,PlayerTwoId,PlayerThreeId,PlayerFourId,PlayerOneBattleScore,PlayerTwoBattleScore,PlayerThreeBattleScore,PlayerFourBattleScore,PlayerOneSportsmanshipScore,PlayerTwoSportsmanshipScore,PlayerThreeSportsmanshipScore,PlayerFourSportsmanshipScore,Table")] PairRoundMatchupEditViewModel pairRoundMatchupvm) { if (id != pairRoundMatchupvm.Id) { return(NotFound()); } var playerOne = await _context.Players.SingleOrDefaultAsync(p => p.Id == pairRoundMatchupvm.PlayerOneId); var playerTwo = await _context.Players.SingleOrDefaultAsync(p => p.Id == pairRoundMatchupvm.PlayerTwoId); var playerThree = await _context.Players.SingleOrDefaultAsync(p => p.Id == pairRoundMatchupvm.PlayerThreeId); var playerFour = await _context.Players.SingleOrDefaultAsync(p => p.Id == pairRoundMatchupvm.PlayerFourId); var roundMatchup = new PairRoundMatchup() { Id = pairRoundMatchupvm.Id, RoundNo = pairRoundMatchupvm.RoundNo, PlayerOne = playerOne, PlayerOneBattleScore = pairRoundMatchupvm.PlayerOneBattleScore, PlayerOneSportsmanshipScore = pairRoundMatchupvm.PlayerOneSportsmanshipScore, PlayerTwo = playerTwo, PlayerTwoBattleScore = pairRoundMatchupvm.PlayerTwoBattleScore, PlayerTwoSportsmanshipScore = pairRoundMatchupvm.PlayerTwoSportsmanshipScore, PlayerThree = playerThree, PlayerThreeBattleScore = pairRoundMatchupvm.PlayerThreeBattleScore, PlayerThreeSportsmanshipScore = pairRoundMatchupvm.PlayerThreeSportsmanshipScore, PlayerFour = playerFour, PlayerFourBattleScore = pairRoundMatchupvm.PlayerFourBattleScore, PlayerFourSportsmanshipScore = pairRoundMatchupvm.PlayerFourSportsmanshipScore, Table = pairRoundMatchupvm.Table }; if (ModelState.IsValid) { try { _context.Update(roundMatchup); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchup.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(AllRounds))); } return(View(pairRoundMatchupvm)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,PlayerOneId,PlayerTwoId,PlayerThreeId,PlayerFourId,CurrentRound")] AdminEditRoundMatchupsViewModel roundMatchup) { if (id != roundMatchup.Id) { return(NotFound()); } PairRoundMatchup updatedPairRoundMatchup = null; RoundMatchup updatedRoundMatchup = null; if (_context.RoundMatchups.Find(id) is PairRoundMatchup) { updatedPairRoundMatchup = _context.RoundMatchups.Find(id) as PairRoundMatchup; updatedPairRoundMatchup.PlayerOne = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerOneId); updatedPairRoundMatchup.PlayerTwo = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerTwoId); updatedPairRoundMatchup.PlayerThree = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerThreeId); updatedPairRoundMatchup.PlayerFour = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerFourId); } else { updatedRoundMatchup = _context.RoundMatchups.Find(id); updatedRoundMatchup.PlayerOne = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerOneId); updatedRoundMatchup.PlayerTwo = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerTwoId); } if (ModelState.IsValid) { try { if (updatedPairRoundMatchup != null) { _context.Update(updatedPairRoundMatchup); } else { _context.Update(updatedRoundMatchup); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchup.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(roundMatchup)); }
public ActionResult ValidateAllRoundMatchups() { List <List <string> > errors = RoundMatchupActions.GetRoundMatchupErrors(_context); TempData["DuplicatePlayers"] = string.Join(" | ", errors[0]); TempData["DuplicateOpponents"] = string.Join(" | ", errors[1]); TempData["OverallocatedPlayers"] = string.Join(" | ", errors[2]); TempData["UnallocatedPlayers"] = string.Join(" | ", errors[3]); return(RedirectToAction(nameof(AllRounds))); }
public ActionResult ValidateAllRoundMatchups() { List <List <string> > errors = RoundMatchupActions.GetRoundMatchupErrors(_context); if (errors[0].Count == 0 && errors[1].Count == 0 && errors[2].Count == 0 && errors[3].Count == 0) { TempData["Status"] = "You're good to go!"; } TempData["DuplicateOpponents"] = string.Join(" | ", errors[1]); TempData["OverallocatedPlayers"] = string.Join(" | ", errors[2]); TempData["UnallocatedPlayers"] = string.Join(" | ", errors[3]); return(RedirectToAction(nameof(AllRounds))); }
// GET: AdminMatchups public async Task <IActionResult> Index() { int lastRoundNo = RoundMatchupActions.GetLastRoundNo(_context); ViewData["Errors"] = TempData["Errors"]; ViewData["DuplicateOpponents"] = TempData["DuplicateOpponents"]; ViewData["OverallocatedPlayers"] = TempData["OverallocatedPlayers"]; ViewData["UnallocatedPlayers"] = TempData["UnallocatedPlayers"]; var roundMatchups = _context.RoundMatchups.Where(r => !(r is PairRoundMatchup)).Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).ToList(); var pairRoundMatchups = _context.PairRoundMatchups.Where(r => r.RoundNo == lastRoundNo).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Include(r => r.PlayerThree).Include(r => r.PlayerFour).ToList(); return(View(roundMatchups.Union(pairRoundMatchups))); }
public ActionResult DisplayNextPairRound() { List <Player> activePlayers = _context.Players.Where(p => p.Active == true).Where(p => p.Bye == false).ToList(); if ((activePlayers.Count() % 4) != 0) { TempData["Errors"] = "You are attempting to generate a round with a number of players indivisible by four, choose the players that should have a bye and retry"; return(RedirectToAction(nameof(Index), "Players")); } if (RoundMatchupActions.GenerateNextPairRound(_context) == false) { TempData["Errors"] = "There are no unique matchups left, manual selection will be required (Random Matchups have been allocated where opponents from last round are teammates)"; } return(RedirectToAction(nameof(Index), "Admin")); }
public ActionResult DisplayNextRound() { List <Player> activePlayers = _context.Players.Where(p => p.Active == true).Where(p => p.Bye == false).ToList(); if ((activePlayers.Count() % 2) != 0) { TempData["Errors"] = "You are attempting to generate a round with an odd number of players, choose the player that should have a bye and retry"; return(RedirectToAction(nameof(Index), "Players")); } if (RoundMatchupActions.GenerateNextRound(_context) == false) { TempData["Errors"] = "There are no unique matchups left, manual selection will be required (Matchups are generated based on most evenly skilled players according to BattleScore, with no regard for previous opponents)"; } return(RedirectToAction(nameof(Index), "Admin")); }
// GET: AdminMatchups public async Task <IActionResult> Index(int?roundNumber) { int? currentRound; string selectedRound; List <RoundMatchup> roundMatchups = new List <RoundMatchup>(); List <PairRoundMatchup> pairRoundMatchups = new List <PairRoundMatchup>(); if (roundNumber == 0) { roundMatchups = await _context.RoundMatchups.Include(r => r.PlayerOne).Include(r => r.PlayerTwo).OrderByDescending(r => r.PlayerOne.BattleScore).ToListAsync(); selectedRound = "all"; } else { if (roundNumber == null) { currentRound = RoundMatchupActions.GetLastRoundNo(_context); } else { currentRound = roundNumber; } roundMatchups = await _context.RoundMatchups.Where(r => !(r is PairRoundMatchup)).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Where(r => r.RoundNo == currentRound).ToListAsync(); pairRoundMatchups = await _context.PairRoundMatchup.Where(r => r.RoundNo == currentRound).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Include(r => r.PlayerThree).Include(r => r.PlayerFour).ToListAsync(); selectedRound = currentRound.ToString(); } AdminViewModel avm = new AdminViewModel { RoundMatchup = pairRoundMatchups, NoOfRounds = _context.RoundMatchups.Select(r => r.RoundNo).ToArray(), CurrentRound = selectedRound }; //If there were no pair round matchups, instead send through the standard round matchups if (avm.RoundMatchup.Count() == 0) { avm.RoundMatchup = roundMatchups; } ViewData["DuplicatePlayers"] = TempData["DuplicatePlayers"]; ViewData["DuplicateOpponents"] = TempData["DuplicateOpponents"]; ViewData["OverallocatedPlayers"] = TempData["OverallocatedPlayers"]; ViewData["UnallocatedPlayers"] = TempData["UnallocatedPlayers"]; return(View(avm)); }
//Reset the matchups public ActionResult ResetRoundMatchups() { int roundNo = RoundMatchupActions.GetLastRoundNo(_context); Boolean pairRoundMatchup = false; foreach (RoundMatchup roundMatchup in _context.RoundMatchups.Where(r => r.RoundNo == roundNo).ToList()) { if (roundMatchup is PairRoundMatchup) { pairRoundMatchup = true; } _context.Remove(roundMatchup); } _context.SaveChanges(); if (pairRoundMatchup == true) { RoundMatchupActions.GenerateNextPairRound(_context); } else { RoundMatchupActions.GenerateNextRound(_context); } return(RedirectToAction(nameof(Index), "Admin")); }
//Generate the RoundMatchups public ActionResult GenerateRoundMatchups() { RoundMatchupActions.GenerateNextRound(_context); return(RedirectToAction("Index", "Admin")); }
public ActionResult DisplayNextPairRound() { RoundMatchupActions.GenerateNextPairRound(_context); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,PlayerOneId,PlayerTwoId,PlayerThreeId,PlayerFourId,CurrentRound")] AdminEditRoundMatchupsViewModel roundMatchup) { if (id != roundMatchup.Id) { return(NotFound()); } //Check if a player is versing themself or on a team with themself in a standard round if (roundMatchup.PlayerThreeId == 0.5 && roundMatchup.PlayerFourId == 0.5) { if (roundMatchup.PlayerOneId == roundMatchup.PlayerTwoId) { TempData["Errors"] = "A player cannot verse themself or be on a team with themself"; roundMatchup.Players = _context.Players.ToList(); return(View(roundMatchup)); } } //Check if a player is versing themself or on a team with themself in a pair round else if (roundMatchup.PlayerOneId == roundMatchup.PlayerTwoId || roundMatchup.PlayerOneId == roundMatchup.PlayerThreeId || roundMatchup.PlayerOneId == roundMatchup.PlayerFourId || roundMatchup.PlayerTwoId == roundMatchup.PlayerThreeId || roundMatchup.PlayerTwoId == roundMatchup.PlayerFourId || roundMatchup.PlayerThreeId == roundMatchup.PlayerFourId) { TempData["Errors"] = "A player cannot verse themself or be on a team with themself"; roundMatchup.Players = _context.Players.ToList(); return(View(roundMatchup)); } PairRoundMatchup updatedPairRoundMatchup = null; RoundMatchup updatedRoundMatchup = null; if (_context.RoundMatchups.Find(id) is PairRoundMatchup) { updatedPairRoundMatchup = _context.RoundMatchups.Include(p => p.PlayerOne).Include(p => p.PlayerTwo).SingleOrDefault(r => r.Id == id) as PairRoundMatchup; updatedPairRoundMatchup.PlayerOne = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerOneId); updatedPairRoundMatchup.PlayerTwo = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerTwoId); updatedPairRoundMatchup.PlayerThree = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerThreeId); updatedPairRoundMatchup.PlayerFour = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerFourId); updatedPairRoundMatchup.Table = roundMatchup.TableNo; } else { updatedRoundMatchup = _context.RoundMatchups.Include(p => p.PlayerOne).Include(p => p.PlayerTwo).SingleOrDefault(r => r.Id == id); updatedRoundMatchup.PlayerOne = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerOneId); updatedRoundMatchup.PlayerTwo = _context.Players.FirstOrDefault(p => p.Id == roundMatchup.PlayerTwoId); updatedRoundMatchup.Table = roundMatchup.TableNo; } if (ModelState.IsValid) { try { if (updatedPairRoundMatchup != null) { _context.Update(updatedPairRoundMatchup); } else { _context.Update(updatedRoundMatchup); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchup.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } roundMatchup.Players = _context.Players.ToList(); return(View(roundMatchup)); }