public async Task <IActionResult> SetGameEligibilityOverride([FromBody] EligibilityOverrideRequest request)
    {
        var leagueYearRecord = await GetExistingLeagueYear(request.LeagueID, request.Year, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.AnyYearNotFinished);

        if (leagueYearRecord.FailedResult is not null)
        {
            return(leagueYearRecord.FailedResult);
        }
        var validResult = leagueYearRecord.ValidResult !;
        var leagueYear  = validResult.LeagueYear;

        MasterGame?masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID);

        if (masterGame is null)
        {
            return(BadRequest());
        }

        if (masterGame.ReleaseDate.HasValue && masterGame.ReleaseDate.Value.Year < leagueYear.Year)
        {
            return(BadRequest("You can't change the override setting of a game that came out in a previous year."));
        }

        var  currentDate        = _clock.GetToday();
        var  eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame, currentDate);
        bool alreadyEligible    = SlotEligibilityService.GameIsEligibleInLeagueYear(eligibilityFactors);
        bool isAllowing         = request.Eligible.HasValue && request.Eligible.Value;
        bool isBanning          = request.Eligible.HasValue && !request.Eligible.Value;

        if (isAllowing && alreadyEligible)
        {
            return(BadRequest("That game is already eligible in your league."));
        }

        if (isBanning && !alreadyEligible)
        {
            return(BadRequest("That game is already ineligible in your league."));
        }

        await _fantasyCriticService.SetEligibilityOverride(leagueYear, masterGame, request.Eligible);

        var refreshedLeagueYear = await _fantasyCriticService.GetLeagueYear(leagueYear.League.LeagueID, request.Year);

        if (refreshedLeagueYear is null)
        {
            return(BadRequest());
        }
        await _fantasyCriticService.UpdatePublisherGameCalculatedStats(refreshedLeagueYear);

        return(Ok());
    }
    public static PossibleMasterGameYear GetPossibleMasterGameYear(MasterGameYear masterGame, IReadOnlyList <PublisherSlot> openNonCounterPickSlots,
                                                                   HashSet <MasterGame> publisherStandardMasterGames, HashSet <MasterGame> myPublisherMasterGames,
                                                                   MasterGameWithEligibilityFactors eligibilityFactors, LocalDate currentDate)
    {
        bool isEligible           = SlotEligibilityService.GameIsEligibleInLeagueYear(eligibilityFactors);
        bool taken                = publisherStandardMasterGames.Contains(masterGame.MasterGame);
        bool alreadyOwned         = myPublisherMasterGames.Contains(masterGame.MasterGame);
        bool isReleased           = masterGame.MasterGame.IsReleased(currentDate);
        bool willRelease          = masterGame.WillRelease();
        bool hasScore             = masterGame.MasterGame.CriticScore.HasValue;
        bool isEligibleInOpenSlot = SlotEligibilityService.GameIsEligibleInOpenSlot(openNonCounterPickSlots, eligibilityFactors);

        PossibleMasterGameYear possibleMasterGame = new PossibleMasterGameYear(masterGame, taken, alreadyOwned, isEligible, isEligibleInOpenSlot, isReleased, willRelease, hasScore);

        return(possibleMasterGame);
    }
示例#3
0
    public bool GameIsEligibleInAnySlot(MasterGame masterGame, LocalDate dateOfPotentialAcquisition)
    {
        var eligibilityFactors = GetEligibilityFactorsForMasterGame(masterGame, dateOfPotentialAcquisition);

        return(SlotEligibilityService.GameIsEligibleInLeagueYear(eligibilityFactors));
    }