public async Task <IActionResult> ResultsEdit(int id, [Bind("Id,RoundNo,PlayerOneId,PlayerTwoId,PlayerOneBattleScore,PlayerTwoBattleScore,PlayerOneSportsmanshipScore,PlayerTwoSportsmanshipScore,Table")] RoundMatchup roundMatchup) { if (id != roundMatchup.Id) { return(NotFound()); } 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(Results))); } return(View(roundMatchup)); }
public async Task <IActionResult> GoToAction(string submitButton, [Bind("Id,RoundNo,NoTableTops,Players,RoundMatchups")] RoundsModel Round) { switch (submitButton) { case "GoToDisplayNextRound": // delegate sending to another controller action if (ModelState.IsValid) { _context.Add(Round); await _context.SaveChangesAsync(); return(RedirectToAction("DisplayNextRound", "RoundMatchups")); } break; case "GoToDisplayNextPairRound": // call another action to perform the cancellation if (ModelState.IsValid) { _context.Add(Round); await _context.SaveChangesAsync(); return(RedirectToAction("DisplayNextPairRound", "RoundMatchups")); } break; default: // If they've submitted the form without a submitButton, // just return the view again. return(View(Round)); } return(View(Round)); }
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> Create([Bind("Id,Name,BattleScore,SportsmanshipScore,Army,Active,EmailAddress,Notes,Paid")] Player player) { if (ModelState.IsValid) { _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(player)); }
public async Task <IActionResult> Create([Bind("Name,Country,AreEliminated,LastModifiedBy,LastModified,Id,CreatedBy,CreatedDate")] Team team) { if (ModelState.IsValid) { _dbContext.Add(team); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(team)); }
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()); } 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(Index))); } return(View(roundMatchup)); }
public async Task <IActionResult> Create([Bind("Id,BattleScoreRatio,SportsmanshipScoreRatio,ArmyScoreRatio")] Tournament tournament) { if (tournament.BattleScoreRatio + tournament.SportsmanshipScoreRatio + tournament.ArmyScoreRatio != 1) { TempData["Errors"] = "The score ratios must add up to a total of 1"; return(View(tournament)); } if (ModelState.IsValid) { _context.Add(tournament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tournament)); }
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)); }
public Task CommitAsync() => _dbContext.SaveChangesAsync();