public static async Task <FantasyFootballBdo> GetFantasyFootball()
        {
            // TODO:Implement Exception Handling.

            FantasyFootballDto responseDto = null;

            using (IApiClient apiClient = new ApiClientJson("https://fantasy.premierleague.com/drf/bootstrap-static"))
            {
                var response = await apiClient.GetAsync <FantasyFootballDto>(null, null);

                // TODO: Error Handling.

                var fileName = $"OT Fantasy Football - {DateTime.UtcNow:yyyy-MMM-dd}.json";

                File.WriteAllText($"wwwroot\\{fileName}", response.ResponseText);

                responseDto = response.ResponseDto;
            }

            var fantasyFootballBdo = new FantasyFootballBdo()
            {
                Teams       = ProcessTeams(responseDto),
                PlayerTypes = ProcessPlayerTypes(responseDto),
                Players     = ProcessPlayers(responseDto)
            };

            return(fantasyFootballBdo);
        }
Exemplo n.º 2
0
        public void Create(FantasyFootballBdo fantasyFootballBdo)
        {
            var utcNow = DateTime.UtcNow;

            var seasonEntity = SeasonsRepository.Get(utcNow);

            if (seasonEntity == null)
            {
                throw new Exception($"There is no Fantasy Football Season covering the Date = {utcNow:yyyy-MMM-dd}.");
            }

            _seasonId = seasonEntity.SeasonId;

            _weekOffset = DateTimeHelper.GetWeekOffset(seasonEntity, utcNow);

            var teamEntity = TeamsRepository.GetFirstOrDefault(entity => (entity.SeasonId == _seasonId) && (entity.WeekOffset == _weekOffset));

            if (teamEntity != null)
            {
                throw new Exception($"There already exists a Weekly Results Set covering the Date = {utcNow:yyyy-MMM-dd}, otherwise known as Season Id = {_seasonId} and Week Offset = {_weekOffset}.");
            }

            _fantasyFootballBdo = fantasyFootballBdo;

            foreach (var teamBdoPair in _fantasyFootballBdo.Teams)
            {
                AddTeam(teamBdoPair.Value);
            }
        }