public async Task <IActionResult> ManagerAssociateGame([FromBody] AssociateGameRequest request)
    {
        var leagueYearPublisherGameRecord = await GetExistingLeagueYearAndPublisherGame(request.PublisherID, request.PublisherGameID, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.YearNotFinishedDraftFinished);

        if (leagueYearPublisherGameRecord.FailedResult is not null)
        {
            return(leagueYearPublisherGameRecord.FailedResult);
        }
        var validResult   = leagueYearPublisherGameRecord.ValidResult !;
        var leagueYear    = validResult.LeagueYear;
        var publisher     = validResult.Publisher;
        var publisherGame = validResult.PublisherGame;

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

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

        AssociateGameDomainRequest domainRequest = new AssociateGameDomainRequest(leagueYear, publisher, publisherGame, masterGame, request.ManagerOverride);

        ClaimResult result = await _gameAcquisitionService.AssociateGame(domainRequest);

        var viewModel = new ManagerClaimResultViewModel(result);

        await _fantasyCriticService.UpdatePublisherGameCalculatedStats(leagueYear);

        return(Ok(viewModel));
    }
 public LeagueAction(AssociateGameDomainRequest action, Instant timestamp)
 {
     Timestamp     = timestamp;
     Publisher     = action.Publisher;
     ActionType    = "Publisher Game Associated";
     Description   = $"Associated publisher game '{action.PublisherGame.GameName}' with master game '{action.MasterGame.GameName}'";
     ManagerAction = true;
 }
Example #3
0
        public async Task <ClaimResult> CanAssociateGame(AssociateGameDomainRequest request)
        {
            List <ClaimError> associationErrors = new List <ClaimError>();
            var supportedYears = await _fantasyCriticRepo.GetSupportedYears();

            var basicErrors = GetBasicErrors(request.Publisher.LeagueYear.League, request.Publisher, supportedYears);

            associationErrors.AddRange(basicErrors);

            var leagueYear = request.Publisher.LeagueYear;
            IReadOnlyList <ClaimError> masterGameErrors = GetMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, request.PublisherGame.CounterPick, false, null);

            associationErrors.AddRange(masterGameErrors);

            IReadOnlyList <Publisher> allPublishers = await _fantasyCriticRepo.GetPublishersInLeagueForYear(request.Publisher.LeagueYear);

            IReadOnlyList <Publisher> publishersForYear = allPublishers.Where(x => x.LeagueYear.Year == leagueYear.Year).ToList();
            IReadOnlyList <Publisher> otherPublishers   = publishersForYear.Where(x => x.User.UserID != request.Publisher.User.UserID).ToList();

            IReadOnlyList <PublisherGame> gamesForYear      = publishersForYear.SelectMany(x => x.PublisherGames).ToList();
            IReadOnlyList <PublisherGame> otherPlayersGames = otherPublishers.SelectMany(x => x.PublisherGames).ToList();

            bool gameAlreadyClaimed = gamesForYear.ContainsGame(request.MasterGame);

            if (!request.PublisherGame.CounterPick)
            {
                if (gameAlreadyClaimed)
                {
                    associationErrors.Add(new ClaimError("Cannot select a game that someone already has.", false));
                }
            }

            if (request.PublisherGame.CounterPick)
            {
                bool otherPlayerHasDraftGame = otherPlayersGames.Where(x => !x.CounterPick).ContainsGame(request.MasterGame);
                if (!otherPlayerHasDraftGame)
                {
                    associationErrors.Add(new ClaimError("Cannot counter pick a game that no other player is publishing.", false));
                }
            }

            var result = new ClaimResult(associationErrors);

            if (result.Overridable && request.ManagerOverride)
            {
                return(new ClaimResult(new List <ClaimError>()));
            }

            return(result);
        }
Example #4
0
        public async Task <ClaimResult> AssociateGame(AssociateGameDomainRequest request)
        {
            ClaimResult claimResult = await CanAssociateGame(request);

            if (!claimResult.Success)
            {
                return(claimResult);
            }

            LeagueAction leagueAction = new LeagueAction(request, _clock.GetCurrentInstant());
            await _fantasyCriticRepo.AddLeagueAction(leagueAction);

            await _fantasyCriticRepo.AssociatePublisherGame(request.Publisher, request.PublisherGame, request.MasterGame);

            return(claimResult);
        }
    public ClaimResult CanAssociateGame(AssociateGameDomainRequest request)
    {
        List <ClaimError> associationErrors = new List <ClaimError>();
        var basicErrors = GetBasicErrors(request.LeagueYear.League, request.Publisher);

        associationErrors.AddRange(basicErrors);
        var leagueYear = request.LeagueYear;

        var currentDate = _clock.GetToday();
        var dateOfPotentialAcquisition = currentDate;

        IReadOnlyList <ClaimError> masterGameErrors = GetGenericSlotMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, false, currentDate,
                                                                                     dateOfPotentialAcquisition, request.PublisherGame.CounterPick, false, false);

        associationErrors.AddRange(masterGameErrors);

        LeaguePublisherGameSet gameSet = new LeaguePublisherGameSet(request.Publisher.PublisherID, request.LeagueYear.Publishers);

        bool thisPlayerAlreadyHas = gameSet.ThisPlayerStandardGames.ContainsGame(request.MasterGame);
        bool gameAlreadyClaimed   = gameSet.OtherPlayerStandardGames.ContainsGame(request.MasterGame);

        if (!request.PublisherGame.CounterPick)
        {
            if (gameAlreadyClaimed)
            {
                associationErrors.Add(new ClaimError("Cannot claim a game that someone already has.", false));
            }

            if (thisPlayerAlreadyHas)
            {
                associationErrors.Add(new ClaimError("Cannot claim a game that you already have.", false));
            }
        }

        if (request.PublisherGame.CounterPick)
        {
            bool otherPlayerHasCounterPick = gameSet.OtherPlayerCounterPicks.ContainsGame(request.MasterGame);
            if (otherPlayerHasCounterPick)
            {
                associationErrors.Add(new ClaimError("Cannot counter-pick a game that someone else has already counter picked.", false));
            }
            bool thisPlayerHasCounterPick = gameSet.ThisPlayerCounterPicks.ContainsGame(request.MasterGame);
            if (thisPlayerHasCounterPick)
            {
                associationErrors.Add(new ClaimError("You already have that counter pick.", false));
            }

            bool otherPlayerHasDraftGame = gameSet.OtherPlayerStandardGames.ContainsGame(request.MasterGame);
            if (!otherPlayerHasDraftGame)
            {
                associationErrors.Add(new ClaimError("Cannot counter pick a game that no other player is publishing.", false));
            }
        }

        var result = new ClaimResult(associationErrors, request.PublisherGame.SlotNumber);

        if (result.Overridable && request.ManagerOverride)
        {
            return(new ClaimResult(request.PublisherGame.SlotNumber));
        }

        return(result);
    }
Example #6
0
        public async Task <IActionResult> ManagerAssociateGame([FromBody] AssociateGameRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var systemWideSettings = await _interLeagueService.GetSystemWideSettings();

            if (systemWideSettings.BidProcessingMode)
            {
                return(BadRequest());
            }

            var publisher = await _publisherService.GetPublisher(request.PublisherID);

            if (publisher.HasNoValue)
            {
                return(BadRequest());
            }

            var league = await _fantasyCriticService.GetLeagueByID(publisher.Value.LeagueYear.League.LeagueID);

            if (league.HasNoValue)
            {
                return(BadRequest());
            }

            var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, publisher.Value.LeagueYear.Year);

            if (leagueYear.HasNoValue)
            {
                return(BadRequest());
            }

            if (!leagueYear.Value.PlayStatus.DraftFinished)
            {
                return(BadRequest("You cannot manually associate games until you draft."));
            }

            if (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Forbid());
            }

            var claimUser = await _userManager.FindByIdAsync(publisher.Value.User.UserID.ToString());

            if (claimUser == null)
            {
                return(BadRequest());
            }

            var publisherGame = publisher.Value.PublisherGames.SingleOrDefault(x => x.PublisherGameID == request.PublisherGameID);

            if (publisherGame == null)
            {
                return(BadRequest());
            }

            Maybe <MasterGame> masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID);

            if (masterGame.HasNoValue)
            {
                return(BadRequest());
            }

            AssociateGameDomainRequest domainRequest = new AssociateGameDomainRequest(publisher.Value, publisherGame, masterGame.Value, request.ManagerOverride);

            ClaimResult result = await _gameAcquisitionService.AssociateGame(domainRequest);

            var viewModel = new ManagerClaimResultViewModel(result);

            await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value);

            return(Ok(viewModel));
        }