Exemple #1
0
    public async Task <IActionResult> BidTimes()
    {
        var nextPublicRevealTime = _clock.GetNextPublicRevealTime();
        var nextBidTime          = _clock.GetNextBidTime();
        var systemWideSettings   = await _interLeagueService.GetSystemWideSettings();

        return(Ok(new BidTimesViewModel(nextPublicRevealTime, nextBidTime, systemWideSettings.ActionProcessingMode)));
    }
Exemple #2
0
    public async Task <ActionResult <ActionedGameSetViewModel> > ActionProcessingDryRun()
    {
        var supportedYears = await _interLeagueService.GetSupportedYears();

        SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues();

        var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay);

        IReadOnlyList <LeagueYear> allLeagueYears = await _adminService.GetLeagueYears(currentYear.Year);

        var nextBidTime   = _clock.GetNextBidTime();
        var actionResults = await _adminService.GetActionProcessingDryRun(systemWideValues, currentYear.Year, nextBidTime, allLeagueYears);

        IEnumerable <LeagueAction> failingActions = actionResults.Results.LeagueActions.Where(x => x.IsFailed);
        var failingActionGames = failingActions.Select(x => x.MasterGameName).Distinct();

        var currentDate = _clock.GetToday();
        var allBids     = await _gameAcquisitionService.GetActiveAcquisitionBids(currentYear, allLeagueYears);

        var distinctBids = allBids.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame);
        List <MasterGameViewModel> pickupGames = distinctBids
                                                 .Select(x => new MasterGameViewModel(x.MasterGame, currentDate, failingActionGames.Contains(x.MasterGame.GameName)))
                                                 .ToList();

        var allDrops = await _gameAcquisitionService.GetActiveDropRequests(currentYear, allLeagueYears);

        var distinctDrops = allDrops.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame);
        List <MasterGameViewModel> dropGames = distinctDrops
                                               .Select(x => new MasterGameViewModel(x.MasterGame, currentDate, failingActionGames.Contains(x.MasterGame.GameName)))
                                               .ToList();

        pickupGames = pickupGames.OrderByDescending(x => x.Error).ThenBy(x => x.MaximumReleaseDate).ToList();
        dropGames   = dropGames.OrderByDescending(x => x.Error).ThenBy(x => x.MaximumReleaseDate).ToList();

        var leagueYearDictionary   = allLeagueYears.ToDictionary(x => x.Key);
        var leagueActionViewModels = actionResults.Results.LeagueActions.Select(x => new LeagueActionViewModel(leagueYearDictionary[x.Publisher.LeagueYearKey], x)).ToList();

        var leagueActionSets             = actionResults.GetLeagueActionSets(true);
        var leagueActionSetViewModels    = leagueActionSets.Select(x => new LeagueActionProcessingSetViewModel(x, currentDate));
        ActionedGameSetViewModel fullSet = new ActionedGameSetViewModel(pickupGames, dropGames, leagueActionViewModels, leagueActionSetViewModels);

        return(Ok(fullSet));
    }
    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);
    }