public async Task <IActionResult> AvailableYears(Guid id)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (currentUser == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var league = await _fantasyCriticService.GetLeagueByID(id);

            if (league.HasNoValue)
            {
                return(BadRequest());
            }

            if (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Unauthorized());
            }

            var supportedYears = await _fantasyCriticService.GetSupportedYears();

            var openYears      = supportedYears.Where(x => x.OpenForCreation).Select(x => x.Year);
            var availableYears = openYears.Except(league.Value.Years);

            return(Ok(availableYears));
        }
Exemple #2
0
        public async Task <IActionResult> LeagueOptions()
        {
            var supportedYears = await _fantasyCriticService.GetSupportedYears();

            var openYears = supportedYears.Where(x => x.OpenForCreation).Select(x => x.Year);
            IReadOnlyList <EligibilityLevel> eligibilityLevels = await _fantasyCriticService.GetEligibilityLevels();

            LeagueOptionsViewModel viewModel = new LeagueOptionsViewModel(openYears, DraftSystem.GetAllPossibleValues(),
                                                                          PickupSystem.GetAllPossibleValues(), ScoringSystem.GetAllPossibleValues(), eligibilityLevels);

            return(Ok(viewModel));
        }
        public async Task <IActionResult> RefreshCriticInfo()
        {
            var supportedYears = await _fantasyCriticService.GetSupportedYears();

            var masterGames = await _fantasyCriticService.GetMasterGames();

            foreach (var masterGame in masterGames)
            {
                if (!masterGame.OpenCriticID.HasValue)
                {
                    continue;
                }

                if (masterGame.IsReleased(_clock) && masterGame.ReleaseDate.HasValue)
                {
                    var year          = masterGame.ReleaseDate.Value.Year;
                    var supportedYear = supportedYears.Single(x => x.Year == year);
                    if (supportedYear.Finished)
                    {
                        continue;
                    }
                }

                var openCriticGame = await _openCriticService.GetOpenCriticGame(masterGame.OpenCriticID.Value);

                if (openCriticGame.HasValue)
                {
                    await _fantasyCriticService.UpdateCriticStats(masterGame, openCriticGame.Value);
                }

                foreach (var subGame in masterGame.SubGames)
                {
                    if (!subGame.OpenCriticID.HasValue)
                    {
                        continue;
                    }

                    var subGameOpenCriticGame = await _openCriticService.GetOpenCriticGame(subGame.OpenCriticID.Value);

                    if (subGameOpenCriticGame.HasValue)
                    {
                        await _fantasyCriticService.UpdateCriticStats(subGame, subGameOpenCriticGame.Value);
                    }
                }
            }

            return(Ok());
        }