Пример #1
0
        private void SingleMatch(Competition competition, Contestant homeTeam, Contestant awayTeam, int round = 0)
        {
            using (var ctx = new Context())
            {
                Match match = new Match();
                match.Date    = DateTime.UtcNow;
                match.Locked  = false;
                match.Playing = true;
                match.Round   = round;
                match.League  = ctx.Competitions.FirstOrDefault(m => m.Name == competition.Name);
                ctx.Matches.Add(match);
                ctx.SaveChanges();

                Match_contestant home = new Match_contestant();
                home.Match      = match;
                home.Contestant = ctx.Contestants.FirstOrDefault(m => m.ID == homeTeam.ID);
                ctx.Match_contestants.Add(home);
                ctx.SaveChanges();

                Match_contestant away = new Match_contestant();
                away.Match      = match;
                away.Contestant = ctx.Contestants.FirstOrDefault(m => m.ID == awayTeam.ID);
                ctx.Match_contestants.Add(away);
                ctx.SaveChanges();
            }
        }
Пример #2
0
 private void CupNextMatch(int current)
 {
     using (var ctx = new Context())
     {
         Match            currentMatch    = ctx.Matches.SingleOrDefault(m => m.ID == current);
         int              starting        = currentMatch.League.Match.OrderBy(m => m.ID).FirstOrDefault().ID;
         int              totalMatches    = currentMatch.League.Match.Count;
         int              round           = currentMatch.Round;
         int              totalRounds     = (int)Math.Log(totalMatches + 1, 2);
         int              redniUKolu      = current - starting - (totalMatches - (int)Math.Pow(2, totalRounds - round + 1));
         int              redniUSljedecem = (redniUKolu + 1) / 2;
         int              total           = starting + totalMatches - ((totalMatches + 1) / (int)Math.Pow(2, round) - redniUSljedecem);
         Match            nextMatch       = ctx.Matches.SingleOrDefault(m => m.ID == total);
         Match_contestant home            = new Match_contestant();
         home.Match = nextMatch;
         var x = HomePoints(currentMatch);
         if (HomePoints(currentMatch) > AwayPoints(currentMatch))
         {
             home.Contestant = currentMatch.Match_contestants.ElementAt(0).Contestant;
         }
         else
         {
             home.Contestant = currentMatch.Match_contestants.ElementAt(1).Contestant;
         }
         ctx.Match_contestants.Add(home);
         ctx.SaveChanges();
         if (nextMatch.Match_contestants.Count == 2)
         {
             nextMatch.Playing = true;
             ctx.SaveChanges();
         }
     }
 }