Пример #1
0
        public ActionResult Edit(MatchBracket matchBracket)
        {
            try
            {
                User user = (User)Session["user"];
                matchBracket.Match = MatchManager.LoadById(matchBracket.MatchId);
                matchBracket.Match.ReportingPlayer = user;
                matchBracket.Match.Winner          = UserManager.LoadById(matchBracket.WinnerId);

                MatchManager.Update(matchBracket.Match);
                matchBracket.Bracket = BracketManager.LoadById(matchBracket.BracketId);

                if (matchBracket.Match.Winner != null)
                {
                    bool isDivisionOver = true;
                    for (int i = matchBracket.Bracket.GetFirstRoundOfDivision() - 1; i < matchBracket.Bracket.GetLastRoundOfDivision(); i++)
                    {
                        isDivisionOver = matchBracket.Bracket.SortedMatches[i].Winner != null;
                        //end the loop if any of the matches are not finished
                        if (isDivisionOver == false)
                        {
                            break;
                        }
                    }

                    if (isDivisionOver)
                    {
                        for (int i = matchBracket.Bracket.GetFirstRoundOfDivision() - 1; i < matchBracket.Bracket.GetLastRoundOfDivision(); i += 2)
                        {
                            Match match = new Match();
                            match.Round = (int)Math.Ceiling((double)matchBracket.Bracket.SortedMatches[i].Round / 2) + matchBracket.Bracket.OriginalRoundCount;
                            if (i + 1 == matchBracket.Bracket.GetLastRoundOfDivision())
                            {
                                match.Player1         = matchBracket.Bracket.SortedMatches[i].Winner;
                                match.ReportingPlayer = match.Player1;
                                match.Winner          = match.Player1;
                                match.Division        = matchBracket.Bracket.CurrentDivision + 1;
                            }
                            else
                            {
                                match.Player1  = matchBracket.Bracket.SortedMatches[i].Winner;
                                match.Player2  = matchBracket.Bracket.SortedMatches[i + 1].Winner;
                                match.Division = matchBracket.Bracket.CurrentDivision + 1;
                            }
                            matchBracket.Bracket.Matches.Add(match);
                            MatchManager.Insert(match, matchBracket.Bracket.Id);
                        }
                        matchBracket.Bracket.CurrentDivision++;
                        BracketManager.Update(matchBracket.Bracket);
                    }
                }
                return(RedirectToAction("Details", "Bracket", new { @id = matchBracket.BracketId }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
 public ActionResult Delete(Guid id)
 {
     if (Authenticate.IsAuthenticated())
     {
         return(View(BracketManager.LoadById(id)));
     }
     else
     {
         return(RedirectToAction("Login", "User", new { returnurl = HttpContext.Request.Url }));
     }
 }
Пример #3
0
        public MatchBracket(Match match)
        {
            Match   = match;
            Bracket = BracketManager.LoadById(Match.BracketId);
            List <User> users = new List <User>();

            users.Add(match.Player1);
            users.Add(match.Player2);
            Participants = users;
            MatchId      = Match.Id;
            BracketId    = Bracket.Id;
        }
Пример #4
0
 public ActionResult Details(Guid id)
 {
     if (Authenticate.IsAuthenticated())
     {
         Bracket        b  = BracketManager.LoadById(id);
         BracketMatches bm = new BracketMatches(b, b.SortedMatches);
         bm.ViewingUser = (User)Session["user"];
         b.Matches.Where(m => m.Player2 == null).ForEach(m => m.Player2 = new BL.User());
         return(View("Details", bm));
     }
     else
     {
         return(RedirectToAction("Login", "User", new { returnurl = HttpContext.Request.Url }));
     }
 }