public PossibleRoyaleMasterGameViewModel(MasterGameYear masterGame, LocalDate currentDate, RoyaleYearQuarter yearQuarter, bool alreadyOwned, IEnumerable <MasterGameTag> masterGameTags) { MasterGame = new MasterGameYearViewModel(masterGame, currentDate); WillReleaseInQuarter = masterGame.WillReleaseInQuarter(yearQuarter.YearQuarter); AlreadyOwned = alreadyOwned; IsEligible = !LeagueTagExtensions.GetRoyaleClaimErrors(masterGameTags, masterGame.MasterGame, currentDate).Any(); IsReleased = masterGame.MasterGame.IsReleased(currentDate); HasScore = masterGame.MasterGame.CriticScore.HasValue; Cost = masterGame.GetRoyaleGameCost(); }
public async Task <ClaimResult> PurchaseGame(RoyalePublisher publisher, MasterGameYear masterGame) { if (publisher.PublisherGames.Count >= MAX_GAMES) { return(new ClaimResult("Roster is full.", null)); } if (publisher.PublisherGames.Select(x => x.MasterGame).Contains(masterGame)) { return(new ClaimResult("Publisher already has that game.", null)); } if (!masterGame.WillReleaseInQuarter(publisher.YearQuarter.YearQuarter)) { return(new ClaimResult("Game will not release this quarter.", null)); } var now = _clock.GetCurrentInstant(); var currentDate = now.ToEasternDate(); if (masterGame.MasterGame.IsReleased(currentDate)) { return(new ClaimResult("Game has been released.", null)); } if (masterGame.MasterGame.CriticScore.HasValue) { return(new ClaimResult("Game has a score.", null)); } var masterGameTags = await _masterGameRepo.GetMasterGameTags(); var eligibilityErrors = LeagueTagExtensions.GetRoyaleClaimErrors(masterGameTags, masterGame.MasterGame, currentDate); if (eligibilityErrors.Any()) { return(new ClaimResult("Game is not eligible under Royale rules.", null)); } var currentBudget = publisher.Budget; var gameCost = masterGame.GetRoyaleGameCost(); if (currentBudget < gameCost) { return(new ClaimResult("Not enough budget.", null)); } RoyalePublisherGame game = new RoyalePublisherGame(publisher.PublisherID, publisher.YearQuarter, masterGame, now, gameCost, 0m, null); await _royaleRepo.PurchaseGame(game); var nextSlot = publisher.PublisherGames.Count; return(new ClaimResult(nextSlot)); }
public async Task <ActionResult <List <PossibleRoyaleMasterGameViewModel> > > PossibleMasterGames(string?gameName, Guid publisherID) { RoyalePublisher?publisher = await _royaleService.GetPublisher(publisherID); if (publisher is null) { return(NotFound()); } var yearQuarter = await _royaleService.GetYearQuarter(publisher.YearQuarter.YearQuarter.Year, publisher.YearQuarter.YearQuarter.Quarter); if (yearQuarter is null) { return(BadRequest()); } var currentDate = _clock.GetToday(); var masterGameTags = await _interLeagueService.GetMasterGameTags(); var masterGames = await _royaleService.GetMasterGamesForYearQuarter(yearQuarter.YearQuarter); if (!string.IsNullOrWhiteSpace(gameName)) { masterGames = MasterGameSearching.SearchMasterGameYears(gameName, masterGames); } else { masterGames = masterGames .Where(x => x.WillReleaseInQuarter(yearQuarter.YearQuarter)) .Where(x => !x.MasterGame.IsReleased(currentDate)) .Where(x => !LeagueTagExtensions.GetRoyaleClaimErrors(masterGameTags, x.MasterGame, currentDate).Any()) .Take(1000) .ToList(); } var viewModels = masterGames.Select(masterGame => new PossibleRoyaleMasterGameViewModel(masterGame, currentDate, yearQuarter, publisher.PublisherGames.Any(y => y.MasterGame.MasterGame.Equals(masterGame.MasterGame)), masterGameTags)).ToList(); return(viewModels); }