public async Task <ActionResult <ActionedGameSet> > GetCurrentActionedGames() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); var bidResults = await _fantasyCriticService.GetBidProcessingDryRun(systemWideValues, currentYear.Year); IEnumerable <LeagueAction> failingBids = bidResults.LeagueActions.Where(x => x.IsFailed); var failingBidGames = failingBids.Select(x => x.MasterGameName).Distinct(); var dropResults = await _fantasyCriticService.GetDropProcessingDryRun(currentYear.Year); IEnumerable <LeagueAction> failingDrops = dropResults.LeagueActions.Where(x => x.IsFailed); var failingDropGames = failingDrops.Select(x => x.MasterGameName).Distinct(); List <MasterGameViewModel> pickupGames = new List <MasterGameViewModel>(); List <MasterGameViewModel> bidGames = new List <MasterGameViewModel>(); foreach (var supportedYear in supportedYears) { var allBids = await _gameAcquisitionService.GetActiveAcquistitionBids(supportedYear); var distinctBids = allBids.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); var bidVMs = distinctBids.Select(x => new MasterGameViewModel(x.MasterGame, _clock, failingBidGames.Contains(x.MasterGame.GameName))); pickupGames.AddRange(bidVMs); var allDrops = await _gameAcquisitionService.GetActiveDropRequests(supportedYear); var distinctDrops = allDrops.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); var dropVMs = distinctDrops.Select(x => new MasterGameViewModel(x.MasterGame, _clock, failingDropGames.Contains(x.MasterGame.GameName))); bidGames.AddRange(dropVMs); } pickupGames = pickupGames.OrderByDescending(x => x.Error).ThenBy(x => x.SortableEstimatedReleaseDate).ToList(); bidGames = bidGames.OrderByDescending(x => x.Error).ThenBy(x => x.SortableEstimatedReleaseDate).ToList(); ActionedGameSet fullSet = new ActionedGameSet(pickupGames, bidGames); return(Ok(fullSet)); }
public async Task <ActionResult <List <LeagueActionViewModel> > > GetCurrentActionedGames() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); var bidResults = await _fantasyCriticService.GetBidProcessingDryRun(systemWideValues, currentYear.Year); IEnumerable <LeagueAction> failingBids = bidResults.LeagueActions.Where(x => x.IsFailed); var failingBidGames = failingBids.Select(x => x.MasterGameName).Distinct(); var dropResults = await _fantasyCriticService.GetDropProcessingDryRun(currentYear.Year); IEnumerable <LeagueAction> failingDrops = dropResults.LeagueActions.Where(x => x.IsFailed); var failingDropGames = failingDrops.Select(x => x.MasterGameName).Distinct(); List <MasterGame> masterGames = new List <MasterGame>(); foreach (var supportedYear in supportedYears) { var allBids = await _gameAcquisitionService.GetActiveAcquistitionBids(supportedYear); var allDrops = await _gameAcquisitionService.GetActiveDropRequests(supportedYear); masterGames.AddRange(allBids.SelectMany(x => x.Value.Select(y => y.MasterGame))); masterGames.AddRange(allDrops.SelectMany(x => x.Value.Select(y => y.MasterGame))); } masterGames = masterGames.Distinct().ToList(); var failingGames = failingBidGames.Concat(failingDropGames); var vms = masterGames.Distinct().Select(x => new MasterGameViewModel(x, _clock, failingGames.Contains(x.GameName))); return(Ok(vms)); }