Exemple #1
0
        /// <summary>
        /// Gets the list of match dates for all completed matches.
        /// </summary>
        /// <returns>Returns the list of match dates for all completed matches.</returns>
        public List <DateTime> GetMatchDays()
        {
            var matchDates = MatchesPlayed.Where(m => m.MatchDate.HasValue).Select(m => m.MatchDate !.Value.Date).Distinct().ToList();

            matchDates.Sort();
            return(matchDates);
        }
Exemple #2
0
        private RankingList GetUnsortedList(IEnumerable <long> teamIds, DateTime upperDateLimit, out DateTime lastUpdatedOn)
        {
            lastUpdatedOn = DateTime.UtcNow;
            if (MatchesPlayed.Any())
            {
                lastUpdatedOn = MatchesPlayed
                                .Where(m => teamIds.Contains(m.HomeTeamId) || teamIds.Contains(m.GuestTeamId))
                                .Max(m => m.ModifiedOn);
            }
            else if (MatchesToPlay.Any())
            {
                lastUpdatedOn = MatchesToPlay
                                .Where(m => teamIds.Contains(m.HomeTeamId) || teamIds.Contains(m.GuestTeamId))
                                .Max(m => m.ModifiedOn);
            }

            var rankingList = new RankingList {
                UpperDateLimit = upperDateLimit, LastUpdatedOn = lastUpdatedOn
            };

            foreach (var teamId in teamIds)
            {
                var rank = new Rank {
                    Number = -1, TeamId = teamId, MatchesPlayed = MatchesPlayed.Count(m => m.HomeTeamId == teamId || m.GuestTeamId == teamId), MatchesToPlay = MatchesToPlay.Count(m => m.HomeTeamId == teamId || m.GuestTeamId == teamId)
                };

                // upperDateLimit contains the date part (without time), so the MatchDate must also be compared with the date part!
                foreach (var match in MatchesPlayed.Where(m => (m.HomeTeamId == teamId || m.GuestTeamId == teamId) && m.MatchDate.HasValue && m.MatchDate.Value.Date <= upperDateLimit.Date))
                {
                    if (match.HomeTeamId == teamId)
                    {
                        rank.MatchPoints.Home  += match.HomeMatchPoints ?? 0;
                        rank.MatchPoints.Guest += match.GuestMatchPoints ?? 0;

                        rank.SetPoints.Home  += match.HomeSetPoints ?? 0;
                        rank.SetPoints.Guest += match.GuestSetPoints ?? 0;

                        rank.BallPoints.Home  += match.HomeBallPoints ?? 0;
                        rank.BallPoints.Guest += match.GuestBallPoints ?? 0;

                        rank.MatchesWonAndLost.Home  += match.HomeMatchPoints > match.GuestMatchPoints ? 1 : 0;
                        rank.MatchesWonAndLost.Guest += match.HomeMatchPoints < match.GuestMatchPoints ? 1 : 0;
                    }
                    else
                    {
                        rank.MatchPoints.Home  += match.GuestMatchPoints ?? 0;
                        rank.MatchPoints.Guest += match.HomeMatchPoints ?? 0;

                        rank.SetPoints.Home  += match.GuestSetPoints ?? 0;
                        rank.SetPoints.Guest += match.HomeSetPoints ?? 0;

                        rank.BallPoints.Home  += match.GuestBallPoints ?? 0;
                        rank.BallPoints.Guest += match.HomeBallPoints ?? 0;

                        rank.MatchesWonAndLost.Home  += match.HomeMatchPoints < match.GuestMatchPoints ? 1 : 0;
                        rank.MatchesWonAndLost.Guest += match.HomeMatchPoints > match.GuestMatchPoints ? 1 : 0;
                    }
                }
                rankingList.Add(rank);
            }

            return(rankingList);
        }