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());
        }
Exemple #2
0
        public async Task <ActionResult <List <MasterGameViewModel> > > MasterGame(string gameName)
        {
            var masterGames = await _fantasyCriticService.GetMasterGames();

            List <MasterGameViewModel> viewModels;

            if (!string.IsNullOrWhiteSpace(gameName))
            {
                gameName   = gameName.ToLower();
                viewModels = masterGames.Where(x => x.GameName.ToLower().Contains(gameName)).Select(x => new MasterGameViewModel(x)).ToList();
            }
            else
            {
                viewModels = masterGames.Select(x => new MasterGameViewModel(x)).ToList();
            }
            return(viewModels);
        }