Пример #1
0
        private static Game GetOrAddGame(DateTime date, Team team1, Team team2)
        {
            var manager = new GamesManager();
            var game    = manager.GetByTeamsAndDate(team1, team2, date) ?? manager.GetByTeamsAndDate(team2, team1, date);

            if (game == null)
            {
                // Check if game exists but one of the team names is different
                game = manager.GetByHomeTeamAndDate(team1, date);
                if (game != null)
                {
                    SetPossibleNameIfNeeded(game.AwayTeamId, team2);
                }
                else
                {
                    game = manager.GetByAwayTeamAndDate(team2, date);
                    if (game != null)
                    {
                        SetPossibleNameIfNeeded(game.HomeTeamId, team1);
                    }
                    else
                    {
                        game = new Game()
                        {
                            HomeTeamId     = team1.Id,
                            AwayTeamId     = team2.Id,
                            Date           = date,
                            GameSiteRatios = new List <GameSiteRatio>()
                        };
                        manager.Add(game);
                    }
                }
            }

            return(game);
        }