示例#1
0
        public ActionResult Details(int id, int roundId = 0)
        {
            List <TournamentModel> tournaments = GlobalConfig.Connection.GetTournament_All();

            try
            {
                TournamentMVCDetailsModel input = new TournamentMVCDetailsModel();
                TournamentModel           t     = tournaments.Where(x => x.Id == id).First();

                input.TournamentName = t.TournamentName;

                var  orderedRounds = t.Rounds.OrderBy(x => x.First().MatchupRound).ToList();
                bool activeRound   = false;

                for (int i = 0; i < orderedRounds.Count; i++)
                {
                    RoundStatus status = RoundStatus.Locked;

                    if (!activeRound)
                    {
                        if (orderedRounds[i].TrueForAll(x => x.Winner != null))
                        {
                            status = RoundStatus.Complete;
                        }
                        else
                        {
                            status      = RoundStatus.Active;
                            activeRound = true;
                            if (roundId == 0)
                            {
                                // Setting the roundId to be the active round number
                                roundId = i + 1;
                            }
                        }
                    }

                    // "i + 1" because our loop starts at 0, hence "int i = 0"
                    input.Rounds.Add(
                        new RoundMVCModel
                    {
                        RoundName   = "Round " + (i + 1),
                        Status      = status,
                        RoundNumber = i + 1
                    });
                }

                // Converting a 1 based list to a 0 based list for lookup
                input.Matchups = GetMatchups(orderedRounds[roundId - 1], id, roundId);

                return(View(input));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#2
0
        public ActionResult Details(int id, int roundId = 0)
        {
            List <TournamentModel> tournaments = GlobalConfig.Connection.GetTournament_All();

            try
            {
                var             input = new TournamentMVCDetailsModel();
                TournamentModel t     = tournaments.Where(x => x.Id == id).First();

                input.TournamentName = t.TournamentName;
                var orderedRounds = t.Rounds.OrderBy(x => x.First().MatchupRound).ToList();
                var activeFound   = false;

                for (int i = 0; i < orderedRounds.Count; i++)
                {
                    RoundStatus status = RoundStatus.Locked;

                    if (!activeFound)
                    {
                        if (orderedRounds[i].TrueForAll(x => x.Winner != null))
                        {
                            status = RoundStatus.Complete;
                        }
                        else
                        {
                            status      = RoundStatus.Active;
                            activeFound = true;

                            if (roundId == 0)
                            {
                                roundId = i + 1;
                            }
                        }
                    }

                    input.Rounds.Add(
                        new RoundMVCModel
                    {
                        RoundName   = "Round " + (i + 1),
                        Status      = status,
                        RoundNumber = i + 1
                    });
                }


                input.Matchups = GetMatchups(orderedRounds[roundId - 1], id, roundId);

                return(View(input));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }