public async Task <ClaimResult> MakePickupBid(Publisher publisher, MasterGame masterGame, uint bidAmount, LeagueOptions leagueOptions) { if (bidAmount < leagueOptions.MinimumBidAmount) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("That bid does not meet the league's minimum bid.", false) })); } if (bidAmount > publisher.Budget) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You do not have enough budget to make that bid.", false) })); } IReadOnlyList <PickupBid> pickupBids = await _fantasyCriticRepo.GetActivePickupBids(publisher); bool alreadyBidFor = pickupBids.Select(x => x.MasterGame.MasterGameID).Contains(masterGame.MasterGameID); if (alreadyBidFor) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You cannot have two active bids for the same game.", false) })); } var claimRequest = new ClaimGameDomainRequest(publisher, masterGame.GameName, false, false, false, masterGame, null, null); var supportedYears = await _fantasyCriticRepo.GetSupportedYears(); var leagueYear = publisher.LeagueYear; var publishersForYear = await _fantasyCriticRepo.GetPublishersInLeagueForYear(publisher.LeagueYear); Instant nextBidTime = GetNextBidTime(); var claimResult = CanClaimGame(claimRequest, supportedYears, leagueYear, publishersForYear, nextBidTime, true); if (!claimResult.Success) { return(claimResult); } var nextPriority = pickupBids.Count + 1; PickupBid currentBid = new PickupBid(Guid.NewGuid(), publisher, leagueYear, masterGame, bidAmount, nextPriority, _clock.GetCurrentInstant(), null); await _fantasyCriticRepo.CreatePickupBid(currentBid); return(claimResult); }
public async Task <BidProcessingResults> GetBidProcessingDryRun(SystemWideValues systemWideValues, int year) { IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > leaguesAndBids = await _fantasyCriticRepo.GetActivePickupBids(year); IReadOnlyList <Publisher> allPublishers = await _fantasyCriticRepo.GetAllPublishersForYear(year); var supportedYears = await _fantasyCriticRepo.GetSupportedYears(); IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > onlyLeaguesWithBids = leaguesAndBids.Where(x => x.Value.Any()).ToDictionary(x => x.Key, y => y.Value); var publishersInLeagues = allPublishers.Where(x => onlyLeaguesWithBids.ContainsKey(x.LeagueYear)); BidProcessingResults results = _actionProcessingService.ProcessPickupsIteration(systemWideValues, onlyLeaguesWithBids, publishersInLeagues, _clock, supportedYears); return(results); }
public async Task <ClaimResult> MakePickupBid(Publisher publisher, MasterGame masterGame, uint bidAmount) { if (bidAmount > publisher.Budget) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You do not have enough budget to make that bid.", false) })); } IReadOnlyList <PickupBid> pickupBids = await _fantasyCriticRepo.GetActivePickupBids(publisher); bool alreadyBidFor = pickupBids.Select(x => x.MasterGame.MasterGameID).Contains(masterGame.MasterGameID); if (alreadyBidFor) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You cannot have two active bids for the same game.", false) })); } var claimRequest = new ClaimGameDomainRequest(publisher, masterGame.GameName, false, false, masterGame, null, null); var claimResult = await CanClaimGame(claimRequest); if (!claimResult.Success) { return(claimResult); } var nextPriority = pickupBids.Count + 1; PickupBid currentBid = new PickupBid(Guid.NewGuid(), publisher, masterGame, bidAmount, nextPriority, _clock.GetCurrentInstant(), null); await _fantasyCriticRepo.CreatePickupBid(currentBid); return(claimResult); }
public async Task <ClaimResult> MakePickupBid(LeagueYear leagueYear, Publisher publisher, MasterGame masterGame, PublisherGame?conditionalDropPublisherGame, bool counterPick, uint bidAmount) { if (bidAmount < leagueYear.Options.MinimumBidAmount) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("That bid does not meet the league's minimum bid.", false) }, null)); } if (bidAmount > publisher.Budget) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You do not have enough budget to make that bid.", false) }, null)); } IReadOnlyList <PickupBid> pickupBids = await _fantasyCriticRepo.GetActivePickupBids(leagueYear, publisher); bool alreadyBidFor = pickupBids.Select(x => x.MasterGame.MasterGameID).Contains(masterGame.MasterGameID); if (alreadyBidFor) { return(new ClaimResult(new List <ClaimError>() { new ClaimError("You cannot have two active bids for the same game.", false) }, null)); } bool counterPickedGameIsManualWillNotRelease = false; if (counterPick) { var gameBeingCounterPickedOptions = leagueYear.Publishers.Select(x => x.GetPublisherGame(masterGame)) .Where(x => x is not null && !x.CounterPick).SelectNotNull().ToList(); if (gameBeingCounterPickedOptions.Count != 1) { throw new Exception($"Something very strange has happened with bid processing for publisher: {publisher.PublisherID}"); } counterPickedGameIsManualWillNotRelease = gameBeingCounterPickedOptions.Single().ManualWillNotRelease; } var claimRequest = new ClaimGameDomainRequest(leagueYear, publisher, masterGame.GameName, counterPick, counterPickedGameIsManualWillNotRelease, false, false, masterGame, null, null); Instant nextBidTime = _clock.GetNextBidTime(); int?validDropSlot = null; if (conditionalDropPublisherGame is not null) { if (counterPick) { return(new ClaimResult("Cannot make a counter pick bid with a conditional drop.", null)); } var dropResult = await MakeDropRequest(leagueYear, publisher, conditionalDropPublisherGame, true); if (dropResult.Result.IsFailure) { return(new ClaimResult(dropResult.Result.Error, null)); } validDropSlot = conditionalDropPublisherGame.SlotNumber; } var claimResult = CanClaimGame(claimRequest, nextBidTime, validDropSlot, false, false); if (!claimResult.Success) { return(claimResult); } var nextPriority = pickupBids.Count + 1; PickupBid currentBid = new PickupBid(Guid.NewGuid(), publisher, leagueYear, masterGame, conditionalDropPublisherGame, counterPick, bidAmount, nextPriority, _clock.GetCurrentInstant(), null, null, null, null); await _fantasyCriticRepo.CreatePickupBid(currentBid); return(claimResult); }
public async Task <FinalizedActionProcessingResults> GetActionProcessingDryRun(SystemWideValues systemWideValues, int year, Instant processingTime, IReadOnlyList <LeagueYear> allLeagueYears) { IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > leaguesAndBids = await _fantasyCriticRepo.GetActivePickupBids(year, allLeagueYears); IReadOnlyDictionary <LeagueYear, IReadOnlyList <DropRequest> > leaguesAndDropRequests = await _fantasyCriticRepo.GetActiveDropRequests(year, allLeagueYears); var onlyLeaguesWithActions = leaguesAndBids .Where(x => x.Value.Any()).Select(x => x.Key) .Concat(leaguesAndDropRequests.Where(x => x.Value.Any()).Select(x => x.Key)) .Distinct().Select(x => x.Key).ToHashSet(); var publishersInLeagues = allLeagueYears.SelectMany(x => x.Publishers).Where(x => onlyLeaguesWithActions.Contains(x.LeagueYearKey)); var masterGameYears = await _interLeagueService.GetMasterGameYears(year); var masterGameYearDictionary = masterGameYears.ToDictionary(x => x.MasterGame.MasterGameID); FinalizedActionProcessingResults results = _actionProcessingService.ProcessActions(systemWideValues, leaguesAndBids, leaguesAndDropRequests, publishersInLeagues, processingTime, masterGameYearDictionary); return(results); }