Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("BracketID,Name,RoundFormat,CreatedAt,Active,TeamTotal")] BracketTable bracketTable)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bracketTable);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bracketTable));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("id,TeamName,BracketID")] Team team)
        {
            if (ModelState.IsValid)
            {
                _context.Add(team);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(team));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("playerID,playerName")] Player player)
        {
            if (ModelState.IsValid)
            {
                _context.Add(player);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(player));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("id,BracketID,RoundNumber")] Round round)
        {
            if (ModelState.IsValid)
            {
                _context.Add(round);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BracketID"] = new SelectList(_context.Brackets, "id", "BracketName", round.BracketID);
            return(View(round));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("MatchID,MatchNumber,TeamAID,TeamBID,TeamAScore,TeamBScore,WinnerID,BracketID,RoundNumber")] Match match)
        {
            if (ModelState.IsValid)
            {
                _context.Add(match);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BracketID"] = new SelectList(_context.Brackets, "id", "BracketName", match.BracketID);
            ViewData["TeamAID"]   = new SelectList(_context.Teams, "id", "TeamName", match.TeamAID);
            ViewData["TeamBID"]   = new SelectList(_context.Teams, "id", "TeamName", match.TeamBID);
            return(View(match));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("id,BracketName,CreatedAt,TotalRounds")] Bracket bracket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bracket);
                await _context.SaveChangesAsync();

                /*
                 * For loop for TotalRounds * 2
                 * Then Create into Team
                 * id, TeamName=Null, BracketID
                 * string query = "SELECT * FROM Department WHERE DepartmentID = @p0";
                 * var TempQueryData = _context.Teams.FromSql("SET IDENTITY_INSERT [dbo].[Team] ON INSERT INTO[dbo].[Team]([id], [TeamName], [BracketID]) VALUES('" + i + "', ' ', '" + tempID + "') SET IDENTITY_INSERT[dbo].[Team] OFF").ToList();
                 *  Debug.WriteLine("HI: " + i);
                 */

                /* 3 rounds
                 * 2^3 = 8 teams
                 * 1v8, 2v7, 3v6, 4v5
                 * 1/8 v. 2/7, 3/6 v. 4/5
                 * 1/8/2/7 v. 3/6/4/5
                 *
                 */
                int roundtotal = Convert.ToInt32(bracket.TotalRounds);
                int teamlength = (int)Math.Pow(2, roundtotal);
                Debug.WriteLine("Team Total: " + teamlength);

                int         gametotal = teamlength - 1;
                string      tempID    = bracket.id.ToString();
                List <Team> teamList  = new List <Team>();
                for (int i = 0; i < teamlength; i++)
                {
                    var initial = new Team()
                    {
                        TeamName  = " ",
                        BracketID = bracket.id,
                    };
                    teamList.Add(initial);

                    _context.Teams.Add(initial);
                }
                _context.SaveChanges();
                /* Initial Games */
                List <Match> matchList      = new List <Match>();
                List <int>   topHalf        = new List <int>();
                List <int>   bottomHalf     = new List <int>();
                List <int>   TempbottomHalf = new List <int>();

                for (int i = 0; i < teamList.Count(); i++)
                {
                    if (((i % 2) == 0) == true)
                    {
                        topHalf.Add(teamList[i].id);
                    }
                    else if (((i % 2) == 0) == false)
                    {
                        TempbottomHalf.Add(teamList[i].id);
                    }
                    else
                    {
                        Debug.WriteLine("Exception Found");
                    }
                }

                for (int i = TempbottomHalf.Count - 1; i >= 0; i--)
                {
                    bottomHalf.Add(TempbottomHalf[i]);
                }

                for (int x = 0; x < topHalf.Count(); x++)
                {
                    if (topHalf[x] < bottomHalf[x])
                    {
                        var matchInitial = new Match()
                        {
                            BracketID   = bracket.id,
                            TeamAID     = topHalf[x],
                            TeamBID     = bottomHalf[x],
                            RoundNumber = 1,
                            MatchNumber = matchList.Count() + 1,
                        };
                        matchList.Add(matchInitial);
                        _context.Matches.Add(matchInitial);
                        _context.SaveChanges();
                    }
                    else
                    {
                        var matchInitial = new Match()
                        {
                            BracketID   = bracket.id,
                            TeamBID     = topHalf[x],
                            TeamAID     = bottomHalf[x],
                            RoundNumber = 1,
                            MatchNumber = matchList.Count() + 1,
                        };
                        matchList.Add(matchInitial);
                        _context.Matches.Add(matchInitial);
                        _context.SaveChanges();
                    }
                }
                _context.SaveChanges();

                // Non-First Round Games

                /*
                 * for (int i = 1; i < roundtotal - 1; i++)
                 * {
                 *
                 *  // 3 Rounds
                 *  // i = 1
                 *  // 3 - 1 = 2
                 *  // 2 - 0 = 2
                 *  // 2^2 = 4
                 *
                 *  int compute = roundtotal - i;
                 *  int val = (int)Math.Pow(2, compute);
                 *  for (int x = 0; x < val; x++)
                 *  {
                 *      var matchInitial = new Match()
                 *      {
                 *          BracketID = bracket.id,
                 *          RoundNumber = i + 2,
                 *          MatchNumber = matchList.Count() + 1,
                 *      };
                 *      matchList.Add(matchInitial);
                 *      _context.Matches.Add(matchInitial);
                 *      _context.SaveChanges();
                 *  }
                 * }
                 */

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(CreatePlayer), new { id = bracket.id }));
            }
            return(View(bracket));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("id,BracketName,CreatedAt,TotalRounds")] Bracket bracket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bracket);
                await _context.SaveChangesAsync();

                /*
                 * For loop for TotalRounds * 2
                 * Then Create into Team
                 * id, TeamName=Null, BracketID
                 * string query = "SELECT * FROM Department WHERE DepartmentID = @p0";
                 * var TempQueryData = _context.Teams.FromSql("SET IDENTITY_INSERT [dbo].[Team] ON INSERT INTO[dbo].[Team]([id], [TeamName], [BracketID]) VALUES('" + i + "', ' ', '" + tempID + "') SET IDENTITY_INSERT[dbo].[Team] OFF").ToList();
                 *  Debug.WriteLine("HI: " + i);
                 */

                /* 3 rounds
                 * 2^3 = 8 teams
                 * 1v8, 2v7, 3v6, 4v5
                 * 1/8 v. 2/7, 3/6 v. 4/5
                 * 1/8/2/7 v. 3/6/4/5
                 *
                 */
                int roundtotal = Convert.ToInt32(bracket.TotalRounds);
                int teamlength = (int)Math.Pow(2, roundtotal);
                Debug.WriteLine("Team Total: " + teamlength);
                int         firstroundgames = teamlength / 2;
                int         gametotal       = teamlength - 1;
                int         remaininggames  = gametotal - firstroundgames;
                string      tempID          = bracket.id.ToString();
                List <Team> teamList        = new List <Team>();
                for (int i = 0; i < teamlength; i++)
                {
                    var initial = new Team()
                    {
                        TeamName  = " ",
                        BracketID = bracket.id,
                    };
                    teamList.Add(initial);

                    _context.Teams.Add(initial);
                }
                _context.SaveChanges();
                /* Initial Games */
                List <int> topHalf        = new List <int>();
                List <int> tempbottomHalf = new List <int>();
                for (int i = 0; i < teamlength; i++)
                {
                    if (i < (bracket.TotalRounds / 2))
                    {
                        topHalf.Add(teamList[i].id);
                    }
                    else
                    {
                        tempbottomHalf.Add(teamList[i].id);
                    }
                }
                List <int> bottomHalf = new List <int>();
                for (int i = 0; i < bottomHalf.Count(); i++)
                {
                    bottomHalf.Add(tempbottomHalf[bottomHalf.Count() - i - 1]);
                }
                //Create Rounds
                //Bracket, RoundNumber
                List <Round> roundList = new List <Round>();
                List <Match> matchList = new List <Match>();
                for (int i = 0; i < roundtotal; i++)
                {
                    var initial = new Round()
                    {
                        RoundNumber = i + 1,
                        BracketID   = bracket.id,
                    };
                    roundList.Add(initial);

                    _context.Rounds.Add(initial);
                    // First Round Matches
                    for (int x = 0; x < firstroundgames; x++)
                    {
                        try
                        {
                            var matchInitial = new Match()
                            {
                                //MatchNumber, TEAMAID, TEAMBID
                                MatchNumber = x,
                                TeamAID     = topHalf[x],
                                TeamBID     = bottomHalf[x],
                            };
                            matchList.Add(matchInitial);
                            _context.Matches.Add(matchInitial);
                        }
                        catch (ArgumentOutOfRangeException ex)
                        {
                            Debug.WriteLine("Out of Range Detected");
                        }
                    }
                }
                _context.SaveChanges();



                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(CreatePlayer), new { id = bracket.id }));
            }
            return(View(bracket));
        }