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)); }
//GET: AllRoundsEdit (Edit one round) public async Task <IActionResult> AllRoundsEdit(int?id) { if (id == null) { return(NotFound()); } var roundMatchup = await _context.RoundMatchups.Include(r => r.PlayerOne).Include(r => r.PlayerTwo).SingleOrDefaultAsync(m => m.Id == id); var players = await _context.Players.ToListAsync(); if (roundMatchup is PairRoundMatchup) { var pairRoundMatchup = roundMatchup as PairRoundMatchup; var prmevm = new PairRoundMatchupEditViewModel() { Id = pairRoundMatchup.Id, RoundNo = pairRoundMatchup.RoundNo, PlayerOneId = pairRoundMatchup.PlayerOne.Id, PlayerOneBattleScore = pairRoundMatchup.PlayerOneBattleScore, PlayerOneSportsmanshipScore = pairRoundMatchup.PlayerOneSportsmanshipScore, PlayerTwoId = pairRoundMatchup.PlayerTwo.Id, PlayerTwoBattleScore = pairRoundMatchup.PlayerTwoBattleScore, PlayerTwoSportsmanshipScore = pairRoundMatchup.PlayerTwoSportsmanshipScore, PlayerThreeId = pairRoundMatchup.PlayerThree.Id, PlayerThreeBattleScore = pairRoundMatchup.PlayerThreeBattleScore, PlayerThreeSportsmanshipScore = pairRoundMatchup.PlayerThreeSportsmanshipScore, PlayerFourId = pairRoundMatchup.PlayerFour.Id, PlayerFourBattleScore = pairRoundMatchup.PlayerFourBattleScore, PlayerFourSportsmanshipScore = pairRoundMatchup.PlayerFourSportsmanshipScore, Table = pairRoundMatchup.Table, Players = players }; return(View("PairRoundMatchupEdit", prmevm)); } else { var arevm = new RoundMatchupEditViewModel() { Id = roundMatchup.Id, RoundNo = roundMatchup.RoundNo, PlayerOneId = roundMatchup.PlayerOne.Id, PlayerOneBattleScore = roundMatchup.PlayerOneBattleScore, PlayerOneSportsmanshipScore = roundMatchup.PlayerOneSportsmanshipScore, PlayerTwoId = roundMatchup.PlayerTwo.Id, PlayerTwoBattleScore = roundMatchup.PlayerTwoBattleScore, PlayerTwoSportsmanshipScore = roundMatchup.PlayerTwoSportsmanshipScore, Table = roundMatchup.Table, Players = players }; return(View("RoundMatchupEdit", arevm)); } }
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()); } //Check if a player is versing themself or on a team with themself if (pairRoundMatchupvm.PlayerOneId == pairRoundMatchupvm.PlayerTwoId || pairRoundMatchupvm.PlayerOneId == pairRoundMatchupvm.PlayerThreeId || pairRoundMatchupvm.PlayerOneId == pairRoundMatchupvm.PlayerFourId || pairRoundMatchupvm.PlayerTwoId == pairRoundMatchupvm.PlayerThreeId || pairRoundMatchupvm.PlayerTwoId == pairRoundMatchupvm.PlayerFourId || pairRoundMatchupvm.PlayerThreeId == pairRoundMatchupvm.PlayerFourId) { TempData["Errors"] = "A player cannot verse themself or be on a team with themself"; pairRoundMatchupvm.Players = _context.Players.ToList(); return(View(pairRoundMatchupvm)); } 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(); if (playerOne != null) { PlayerActions.SetPlayerScores((int)pairRoundMatchupvm.PlayerOneId, _context); } if (playerTwo != null) { PlayerActions.SetPlayerScores((int)pairRoundMatchupvm.PlayerTwoId, _context); } if (playerThree != null) { PlayerActions.SetPlayerScores((int)pairRoundMatchupvm.PlayerThreeId, _context); } if (playerFour != null) { PlayerActions.SetPlayerScores((int)pairRoundMatchupvm.PlayerFourId, _context); } } catch (DbUpdateConcurrencyException) { if (!RoundMatchupActions.RoundMatchupsExists(roundMatchup.Id, _context)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(AllRounds))); } pairRoundMatchupvm.Players = _context.Players.ToList(); return(View(pairRoundMatchupvm)); }