public async Task <IActionResult> AdminEdit(int id, [Bind("Id,PlayerOneId,PlayerTwoId,TableNo")] AdminEditRoundMatchupsViewModel roundMatchup)
        {
            if (id != roundMatchup.Id)
            {
                return(NotFound());
            }

            RoundMatchups 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);
            updatedRoundMatchup.Table     = roundMatchup.TableNo;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(updatedRoundMatchup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoundMatchupsExists(roundMatchup.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Admin)));
            }
            return(View(roundMatchup));
        }
示例#2
0
        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));
        }
        //GET: AdminEdit
        public async Task <IActionResult> Edit(int?id)
        {
            var aevm = new AdminEditRoundMatchupsViewModel();


            if (id == null)
            {
                return(NotFound());
            }

            var roundMatchup = await _context.RoundMatchups.Where(r => r.Id == id).Where(r => !(r is PairRoundMatchup)).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).SingleOrDefaultAsync();

            var pairRoundMatchup = await _context.PairRoundMatchups.Where(r => r.Id == id).Include(r => r.PlayerOne).Include(r => r.PlayerTwo).Include(r => r.PlayerThree).Include(r => r.PlayerFour).SingleOrDefaultAsync();

            if (roundMatchup != null)
            {
                aevm = new AdminEditRoundMatchupsViewModel
                {
                    Id          = roundMatchup.Id,
                    PlayerOneId = roundMatchup.PlayerOne.Id,
                };
                //Handling bye roundmatchup
                //If this roundmatchup is not a bye, set PlayerTwoId in the view model to the value of PlayerTwo.Id in the roundMatchup
                if (roundMatchup.PlayerTwo != null)
                {
                    aevm.TableNo     = roundMatchup.Table;
                    aevm.PlayerTwoId = roundMatchup.PlayerTwo.Id;
                }
                //If this roundmatchup is a bye, set PlayerTwoId in the view model to 0.5 (not 0 because that could be an Id)
                else
                {
                    aevm.PlayerTwoId = 0.5;
                }
            }
            else if (pairRoundMatchup != null)
            {
                aevm = new AdminEditRoundMatchupsViewModel
                {
                    Id          = pairRoundMatchup.Id,
                    PlayerOneId = pairRoundMatchup.PlayerOne.Id,
                };
                //Handling bye roundmatchup
                //If this roundmatchup is not a bye, set PlayerTwoId, PlayerFourId in the view model to the value of PlayerTwo.Id in the roundMatchup
                if (pairRoundMatchup.PlayerTwo != null)
                {
                    aevm.PlayerTwoId   = pairRoundMatchup.PlayerTwo.Id;
                    aevm.PlayerThreeId = pairRoundMatchup.PlayerThree.Id;
                    aevm.PlayerFourId  = pairRoundMatchup.PlayerFour.Id;
                    aevm.TableNo       = pairRoundMatchup.Table;
                }
                //If this roundmatchup is a bye, set PlayerTwoId, PlayerFourId in the view model to 0.5 (not 0 because that could be an Id)
                else
                {
                    aevm.PlayerTwoId   = 0.5;
                    aevm.PlayerThreeId = 0.5;
                    aevm.PlayerFourId  = 0.5;
                }
            }
            if (aevm == null)
            {
                return(NotFound());
            }
            aevm.Players = await _context.Players.ToListAsync();

            return(View(aevm));
        }
        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));
        }