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)); }
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)); }
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 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)); }