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));
        }
Beispiel #2
0
        //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));
            }
        }
Beispiel #3
0
        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));
        }