Exemple #1
0
        public int ScoreThisRoundBeforeDateTime(DateTime lastQualifiedDateTime)
        {
            var score = 0;

            if (Round.StartActive >= CETDateHelper.GetCurrentCETDateTime())
            {
                return(score);   //has not become active no need to calculate the other items
            }
            foreach (var roundTeam in Round.TeamsInRound.Where(rt => rt.DateTimeQualified <= lastQualifiedDateTime))
            {
                if (!Round.IsRanked)
                {
                    if (RoundPrediction.Teams.Any(rp => rp.Team.Id == roundTeam.Team.Id))
                    {
                        score += Round.PointPerCorrectTeam;
                    }
                }
                else
                {
                    //Also needs the correct order of the teams
                    if (
                        RoundPrediction.Teams.Any(
                            rp => rp.Rank == roundTeam.Rank && rp.Team.Id == roundTeam.Team.Id))
                    {
                        score += Round.PointPerCorrectTeam;
                    }
                }
            }
            return(score);
        }
Exemple #2
0
 public ActionResult Index()
 {
     using (var context = new TippeContext())
     {
         var scoreResultService = new ScoreResultservice(context.Users.ToList(),
                                                         context.MatchPredictions.ToList(), context.Matches.ToList(), context.Rounds.Include("TeamsInRound").ToList(), context.RoundPredictions.Include("Teams").ToList());
         var earlierGames   = new List <GameViewModel>();
         var todaysGames    = new List <GameViewModel>();
         var upcomingGames  = new List <GameViewModel>();
         var endgame        = new List <RoundViewModel>();
         var cetDateTimeNow = CETDateHelper.GetCurrentCETDateTime();
         foreach (var game in context.Matches.Include("HomeTeam").Include("AwayTeam").ToList().Where(d => d.Date != null && d.Date.Value.Date < cetDateTimeNow.Date).OrderByDescending(g => g.Date))
         {
             earlierGames.Add(new GameViewModel
             {
                 Game           = game,
                 GameUserScores = scoreResultService.GetGameUserScoresForGame(game)
             });
         }
         foreach (var game in context.Matches.Include("HomeTeam").Include("AwayTeam").ToList().Where(d => d.Date != null && d.Date.Value.Date == cetDateTimeNow.Date).OrderBy(g => g.Date))
         {
             todaysGames.Add(new GameViewModel
             {
                 Game           = game,
                 GameUserScores = scoreResultService.GetGameUserScoresForGame(game)
             });
         }
         foreach (var game in context.Matches.Include("HomeTeam").Include("AwayTeam").ToList().Where(d => d.Date != null && d.Date.Value.Date > cetDateTimeNow.Date).OrderBy(g => g.Date))
         {
             upcomingGames.Add(new GameViewModel
             {
                 Game           = game,
                 GameUserScores = scoreResultService.GetGameUserScoresForGame(game)
             });
         }
         foreach (var round in context.Rounds.Include("TeamsInRound").Include("TeamsInRound.Team").ToList())
         {
             List <RoundTeam> teamsinround;
             if (round.IsRanked)
             {
                 teamsinround = round.TeamsInRound.OrderBy(r => r.Rank).ToList();
             }
             else
             {
                 teamsinround = round.TeamsInRound.OrderBy(r => r.Team.Name).ToList();
             }
             var user            = context.Users.First();
             var roundPrediction =
                 context.RoundPredictions.First(rp => rp.UserId == user.Id && rp.RoundId == round.Id);
             endgame.Add(new RoundViewModel
             {
                 Round           = round,
                 RoundUserScores = scoreResultService.GetRoundUserScoresForRound(round),
                 RoundTeams      = teamsinround,
                 NumTeams        = roundPrediction != null ? context.RoundPredictionTeams.Count(rpt => rpt.RoundPredictionId == roundPrediction.Id) : teamsinround.Count()
             });
         }
         var ivm = new IndexViewModel
         {
             EarlierGames  = earlierGames,
             TodaysGames   = todaysGames,
             UpcomingGames = upcomingGames,
             EndGame       = endgame
         };
         return(View(ivm));
     }
 }