public CommandDispatcher(string typeOfData, string[] dataArgs)
    {
        switch (typeOfData)
        {
        case "team":

            IImport importTeam = new ImportTeam(dataArgs[0], dataArgs[1],
                                                dataArgs[2], dataArgs[3], dataArgs[4]);
            importTeam.Execute();
            break;

        case "game":
            string   competition   = dataArgs[0];
            string   homeTeam      = dataArgs[1];
            string   awayTeam      = dataArgs[2];
            int      homeTeamGoals = int.Parse(dataArgs[3]);
            int      awayTeamGoals = int.Parse(dataArgs[4]);
            DateTime dateOfGame    = DateTime.Parse(dataArgs[5]);

            IImport importGames = new ImportGames(competition, homeTeam, awayTeam,
                                                  homeTeamGoals, awayTeamGoals, dateOfGame);
            importGames.Execute();
            break;

        case "town":

            string  townName    = dataArgs[0];
            string  countryName = dataArgs[1];
            IImport importTown  = new ImportTown(townName, countryName);
            importTown.Execute();
            break;

        case "country":
            IImport importCountry = new ImportCountry(dataArgs[0]);
            importCountry.Execute();
            break;

        case "competition":
            IImport importCompetition = new ImportCompetition(dataArgs[0]);
            importCompetition.Execute();

            break;

        case "colours":
            IImport importColours = new ImportColour(dataArgs[0]);
            importColours.Execute();
            break;
        }
    }
 public AdminModel()
 {
     ImportCompetition = new ImportCompetition();
     MatchList         = new List <Match>();
 }
Beispiel #3
0
        public async Task ImportCompetitionFromFIFA(ImportCompetition importCompetition)
        {
            var queryBuilder = new QueryBuilder
            {
                { "IdCompetition", importCompetition.CompetitionId.ToString() },
                { "IdSeason", importCompetition.SeasonId.ToString() }
            };

            if (importCompetition.StageId.HasValue)
            {
                queryBuilder.Add("idStage", importCompetition.StageId.Value.ToString());
            }

            var message = await _client.GetAsync($"https://api.fifa.com/api/v1/calendar/matches?{queryBuilder.ToQueryString()}");

            var content = await message.Content.ReadAsStringAsync();

            var response = JsonSerializer.Deserialize <FifaResponse <Model.FIFA.Match> >(content);

            if (!response.Results.Any())
            {
                return;
            }

            var competitionId        = $"{importCompetition.CompetitionId}/{importCompetition.SeasonId}";
            var competitionResponses = await _awsJsInterop.GraphQlAsync <CompetitionResponses>(FootballChampionship.Model.Queries.GET_COMPETITION, new { id = competitionId, owner = "null" });

            var competition = competitionResponses.GetCompetition;

            if (competition == null)
            {
                competition = new Competition
                {
                    Matches = new AwsGraphQlList <FootballChampionship.Model.Match>
                    {
                        Items = new List <FootballChampionship.Model.Match>()
                    },
                    From = DateTimeOffset.MaxValue
                };
            }

            var mutation = competition.Id == null ? Model.Mutations.CREATE_COMPETITION : Model.Mutations.UPDATE_COMPETITION;

            var matches    = response.Results.OrderBy(r => r.Date);
            var firstMatch = matches.First();
            var lastMatch  = matches.Last();

            var fromDate = competition.From;
            var toDate   = competition.To;

            var importedMatchList = competition.Matches.Items;

            if (importedMatchList.Any())
            {
                var firstDate = importedMatchList.First().BeginAt;
                fromDate = firstDate < fromDate ? firstDate : fromDate;
                var lastDate = importedMatchList.Last().BeginAt;
                toDate = lastDate > toDate ? lastDate : toDate;
            }

            competitionResponses = await _awsJsInterop.GraphQlAsync <CompetitionResponses>(mutation, new
            {
                input = new
                {
                    Id             = competitionId,
                    Title          = firstMatch.CompetitionName.First().Description,
                    From           = fromDate.Date.ToAwsDate(),
                    To             = toDate.Date.ToAwsDate(),
                    localizedNames = firstMatch.CompetitionName.Select(n => new LocalizedName {
                        Locale = n.Locale, Value = n.Description
                    })
                }
            });

            competition = competition.Id == null ? competitionResponses.CreateCompetition : competitionResponses.UpdateCompetition;

            competition.Matches = new AwsGraphQlList <FootballChampionship.Model.Match>
            {
                Items = importedMatchList.ToList()
            };

            CompetitionUpdated?.Invoke(competition);

            foreach (var match in matches)
            {
                await UpdateMatch(competition, match);
            }

            await UpdateMatches(competitionId, competition, queryBuilder, "fr-FR");
            await UpdateMatches(competitionId, competition, queryBuilder, "de-DE");
        }