コード例 #1
0
        public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request, bool managerAction, bool draft, IReadOnlyList <Publisher> publishersForYear)
        {
            Maybe <MasterGameYear> masterGameYear = Maybe <MasterGameYear> .None;

            if (request.MasterGame.HasValue)
            {
                masterGameYear = new MasterGameYear(request.MasterGame.Value, request.Publisher.LeagueYear.Year);
            }

            PublisherGame playerGame = new PublisherGame(request.Publisher.PublisherID, Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, null,
                                                         masterGameYear, request.DraftPosition, request.OverallDraftPosition);

            var supportedYears = await _fantasyCriticRepo.GetSupportedYears();

            LeagueYear leagueYear = request.Publisher.LeagueYear;

            ClaimResult claimResult = CanClaimGame(request, supportedYears, leagueYear, publishersForYear, null, false);

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

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

            await _fantasyCriticRepo.AddPublisherGame(playerGame);

            return(claimResult);
        }
コード例 #2
0
    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));
    }
コード例 #3
0
    public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request, bool managerAction, bool draft, bool drafting)
    {
        MasterGameYear?masterGameYear = null;

        if (request.MasterGame is not null)
        {
            masterGameYear = new MasterGameYear(request.MasterGame, request.LeagueYear.Year);
        }

        ClaimResult claimResult = CanClaimGame(request, null, null, true, drafting);

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

        PublisherGame playerGame = new PublisherGame(request.Publisher.PublisherID, Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, false, null,
                                                     masterGameYear, claimResult.BestSlotNumber !.Value, request.DraftPosition, request.OverallDraftPosition, null, null);

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

        await _fantasyCriticRepo.AddPublisherGame(playerGame);

        return(claimResult);
    }
コード例 #4
0
    public async Task <IActionResult> ManagerClaimGame([FromBody] ClaimGameRequest request)
    {
        var leagueYearPublisherRecord = await GetExistingLeagueYearAndPublisher(request.PublisherID, ActionProcessingModeBehavior.Ban, RequiredRelationship.LeagueManager, RequiredYearStatus.YearNotFinishedDraftFinished);

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

        MasterGame?masterGame = null;

        if (request.MasterGameID.HasValue)
        {
            masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID.Value);
        }

        bool counterPickedGameIsManualWillNotRelease = PlayerGameExtensions.CounterPickedGameIsManualWillNotRelease(leagueYear, request.CounterPick, masterGame, false);
        ClaimGameDomainRequest domainRequest         = new ClaimGameDomainRequest(leagueYear, publisher, request.GameName, request.CounterPick, counterPickedGameIsManualWillNotRelease, request.ManagerOverride, false, masterGame, null, null);
        ClaimResult            result = await _gameAcquisitionService.ClaimGame(domainRequest, true, false, false);

        var viewModel = new ManagerClaimResultViewModel(result);

        await _fantasyCriticService.UpdatePublisherGameCalculatedStats(leagueYear);

        return(Ok(viewModel));
    }
コード例 #5
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);
        }
コード例 #6
0
        public async Task <IActionResult> MakePickupBid([FromBody] PickupBidRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

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

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

            Maybe <LeagueYear> leagueYear = await _fantasyCriticService.GetLeagueYear(publisher.Value.League.LeagueID, publisher.Value.Year);

            if (leagueYear.HasNoValue)
            {
                return(BadRequest());
            }
            if (!leagueYear.Value.PlayStatus.PlayStarted)
            {
                return(BadRequest("Play has not started for that year."));
            }

            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            bool userIsInLeague = await _fantasyCriticService.UserIsInLeague(publisher.Value.League, currentUser);

            bool userIsPublisher = (currentUser.UserID == publisher.Value.User.UserID);

            if (!userIsInLeague || !userIsPublisher)
            {
                return(Forbid());
            }

            var masterGame = await _fantasyCriticService.GetMasterGame(request.MasterGameID);

            if (masterGame.HasNoValue)
            {
                return(BadRequest("That master game does not exist."));
            }

            ClaimResult bidResult = await _fantasyCriticService.MakePickupBid(publisher.Value, masterGame.Value, request.BidAmount);

            var viewModel = new PickupBidResultViewModel(bidResult);

            return(Ok(viewModel));
        }
コード例 #7
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);
        }
コード例 #8
0
        public async Task <ClaimResult> ClaimGame(ClaimGameDomainRequest request)
        {
            PublisherGame playerGame = new PublisherGame(Guid.NewGuid(), request.GameName, _clock.GetCurrentInstant(), request.CounterPick, null, null,
                                                         new MasterGameYear(request.MasterGame.Value, request.Publisher.Year), request.DraftPosition, request.OverallDraftPosition, request.Publisher.Year);

            ClaimResult claimResult = await CanClaimGame(request);

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

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

            await _fantasyCriticRepo.AddPublisherGame(request.Publisher, playerGame);

            return(claimResult);
        }
コード例 #9
0
        public ClaimResult CanClaimGame(ClaimGameDomainRequest request, IEnumerable <SupportedYear> supportedYears, LeagueYear leagueYear,
                                        IEnumerable <Publisher> publishersInLeague, Instant?nextBidTime, bool allowIfFull)
        {
            List <ClaimError> claimErrors = new List <ClaimError>();

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

            claimErrors.AddRange(basicErrors);

            LeagueOptions yearOptions = leagueYear.Options;

            if (request.MasterGame.HasValue && !request.CounterPick)
            {
                var masterGameErrors = GetMasterGameErrors(leagueYear, request.MasterGame.Value, leagueYear.Year, request.CounterPick, false, nextBidTime);
                claimErrors.AddRange(masterGameErrors);
            }

            IReadOnlyList <Publisher> otherPublishers = publishersInLeague.Where(x => x.User.UserID != request.Publisher.User.UserID).ToList();

            IReadOnlyList <PublisherGame> gamesForYear         = publishersInLeague.SelectMany(x => x.PublisherGames).ToList();
            IReadOnlyList <PublisherGame> standardGamesForYear = gamesForYear.Where(x => !x.CounterPick).ToList();
            IReadOnlyList <PublisherGame> thisPlayersGames     = request.Publisher.PublisherGames;
            IReadOnlyList <PublisherGame> otherPlayersGames    = otherPublishers.SelectMany(x => x.PublisherGames).ToList();

            bool gameAlreadyClaimed   = standardGamesForYear.ContainsGame(request);
            bool thisPlayerAlreadyHas = thisPlayersGames.ContainsGame(request);

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

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

                int leagueDraftGames = yearOptions.StandardGames;
                int userDraftGames   = thisPlayersGames.Count(x => !x.CounterPick);
                if (userDraftGames == leagueDraftGames && !allowIfFull)
                {
                    claimErrors.Add(new ClaimError("User's game spaces are filled.", false));
                }
            }

            if (request.CounterPick)
            {
                bool otherPlayerHasCounterPick = otherPlayersGames.Where(x => x.CounterPick).ContainsGame(request);
                if (otherPlayerHasCounterPick)
                {
                    claimErrors.Add(new ClaimError("Cannot counter-pick a game that someone else has already counter-picked.", false));
                }
                bool thisPlayerHasCounterPick = thisPlayersGames.Where(x => x.CounterPick).ContainsGame(request);
                if (thisPlayerHasCounterPick)
                {
                    claimErrors.Add(new ClaimError("You already have that counter-pick.", false));
                }

                bool otherPlayerHasDraftGame = otherPlayersGames.Where(x => !x.CounterPick).ContainsGame(request);

                int leagueCounterPicks = yearOptions.CounterPicks;
                int userCounterPicks   = thisPlayersGames.Count(x => x.CounterPick);
                if (userCounterPicks == leagueCounterPicks)
                {
                    claimErrors.Add(new ClaimError("User's counter pick spaces are filled.", false));
                }

                if (!otherPlayerHasDraftGame)
                {
                    claimErrors.Add(new ClaimError("Cannot counterPick a game that no other player is publishing.", false));
                }
            }

            var result = new ClaimResult(claimErrors);

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

            return(result);
        }
コード例 #10
0
 public ManagerClaimResultViewModel(ClaimResult domain)
 {
     Success     = domain.Success;
     Errors      = domain.Errors.Select(x => x.Error).ToList();
     Overridable = domain.Overridable;
 }
コード例 #11
0
    public ClaimResult CanClaimGame(ClaimGameDomainRequest request, Instant?nextBidTime, int?validDropSlot, bool acquiringNow, bool drafting)
    {
        var currentDate = _clock.GetToday();
        var dateOfPotentialAcquisition = currentDate;

        if (nextBidTime.HasValue)
        {
            dateOfPotentialAcquisition = nextBidTime.Value.ToEasternDate();
        }

        var leagueYear = request.LeagueYear;

        List <ClaimError> claimErrors = new List <ClaimError>();

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

        claimErrors.AddRange(basicErrors);

        if (request.MasterGame is not null)
        {
            var masterGameErrors = GetGenericSlotMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, false, currentDate,
                                                                  dateOfPotentialAcquisition, request.CounterPick, request.CounterPickedGameIsManualWillNotRelease, drafting);
            claimErrors.AddRange(masterGameErrors);
        }

        LeaguePublisherGameSet gameSet = new LeaguePublisherGameSet(request.Publisher.PublisherID, leagueYear.Publishers);
        bool thisPlayerAlreadyHas      = gameSet.ThisPlayerStandardGames.ContainsGame(request);
        bool gameAlreadyClaimed        = gameSet.OtherPlayerStandardGames.ContainsGame(request);

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

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

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

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

        MasterGameWithEligibilityFactors?eligibilityFactors = null;

        if (request.MasterGame is not null)
        {
            eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(request.MasterGame, dateOfPotentialAcquisition);
        }

        var slotResult = SlotEligibilityService.GetPublisherSlotAcquisitionResult(request.Publisher, leagueYear.Options, eligibilityFactors, request.CounterPick, validDropSlot, acquiringNow);

        if (!slotResult.SlotNumber.HasValue)
        {
            claimErrors.AddRange(slotResult.ClaimErrors);
            return(new ClaimResult(claimErrors, null));
        }

        var result = new ClaimResult(claimErrors, slotResult.SlotNumber.Value);

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

        return(result);
    }
コード例 #12
0
        private async Task <ClaimResult> CanClaimGame(ClaimGameDomainRequest request)
        {
            List <ClaimError> claimErrors = new List <ClaimError>();

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

            claimErrors.AddRange(basicErrors);

            var leagueYear = await _fantasyCriticRepo.GetLeagueYear(request.Publisher.League, request.Publisher.Year);

            if (leagueYear.HasNoValue)
            {
                throw new Exception("Something has gone terribly wrong with league years.");
            }

            LeagueOptions yearOptions = leagueYear.Value.Options;

            if (request.MasterGame.HasValue)
            {
                var masterGameErrors = GetMasterGameErrors(leagueYear.Value.Options, request.MasterGame.Value, leagueYear.Value.Year, request.CounterPick);
                claimErrors.AddRange(masterGameErrors);
            }

            IReadOnlyList <Publisher> allPublishers = await _fantasyCriticRepo.GetPublishersInLeagueForYear(request.Publisher.League, request.Publisher.Year);

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

            IReadOnlyList <PublisherGame> gamesForYear      = allPublishers.SelectMany(x => x.PublisherGames).ToList();
            IReadOnlyList <PublisherGame> thisPlayersGames  = request.Publisher.PublisherGames;
            IReadOnlyList <PublisherGame> otherPlayersGames = otherPublishers.SelectMany(x => x.PublisherGames).ToList();

            bool gameAlreadyClaimed = gamesForYear.ContainsGame(request);

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

                int leagueDraftGames = yearOptions.StandardGames;
                int userDraftGames   = thisPlayersGames.Count(x => !x.CounterPick);
                if (userDraftGames == leagueDraftGames)
                {
                    claimErrors.Add(new ClaimError("User's game spaces are filled.", false));
                }
            }

            if (request.CounterPick)
            {
                bool otherPlayerHasCounterPick = otherPlayersGames.Where(x => x.CounterPick).ContainsGame(request);
                if (otherPlayerHasCounterPick)
                {
                    claimErrors.Add(new ClaimError("Cannot counter-pick a game that someone else has already counter-picked.", false));
                }

                bool otherPlayerHasDraftGame = otherPlayersGames.Where(x => !x.CounterPick).ContainsGame(request);

                int leagueCounterPicks = yearOptions.CounterPicks;
                int userCounterPicks   = thisPlayersGames.Count(x => x.CounterPick);
                if (userCounterPicks == leagueCounterPicks)
                {
                    claimErrors.Add(new ClaimError("User's counter pick spaces are filled.", false));
                }

                if (!otherPlayerHasDraftGame)
                {
                    claimErrors.Add(new ClaimError("Cannot counterPick a game that no other player is publishing.", false));
                }
            }

            var result = new ClaimResult(claimErrors);

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

            return(result);
        }
コード例 #13
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));
        }
コード例 #14
0
        public async Task <IActionResult> ManagerDraftGame([FromBody] ManagerDraftGameRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

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

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

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

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

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

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

            if (!leagueYear.Value.PlayStatus.DraftIsActive)
            {
                return(BadRequest("You can't draft a game if the draft isn't active."));
            }

            var nextPublisher = await _fantasyCriticService.GetNextDraftPublisher(leagueYear.Value);

            if (nextPublisher.HasNoValue)
            {
                return(BadRequest("There are no spots open to draft."));
            }

            if (!nextPublisher.Value.Equals(publisher.Value))
            {
                return(BadRequest("That publisher is not next up for drafting."));
            }

            Maybe <MasterGame> masterGame = Maybe <MasterGame> .None;

            if (request.MasterGameID.HasValue)
            {
                masterGame = await _fantasyCriticService.GetMasterGame(request.MasterGameID.Value);
            }

            int?publisherPosition = null;
            int?overallPosition   = null;
            var draftPhase        = await _fantasyCriticService.GetDraftPhase(leagueYear.Value);

            if (draftPhase.Equals(DraftPhase.StandardGames))
            {
                publisherPosition = publisher.Value.PublisherGames.Count(x => !x.CounterPick) + 1;
                var publishers = await _fantasyCriticService.GetPublishersInLeagueForYear(league.Value, leagueYear.Value.Year);

                overallPosition = publishers.SelectMany(x => x.PublisherGames).Count(x => !x.CounterPick) + 1;

                if (request.CounterPick)
                {
                    return(BadRequest("Not drafting counterPicks now."));
                }
            }

            if (draftPhase.Equals(DraftPhase.CounterPicks))
            {
                if (!request.CounterPick)
                {
                    return(BadRequest("Not drafting standard games now."));
                }
            }

            ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(publisher.Value, request.GameName, request.CounterPick, request.ManagerOverride, masterGame, publisherPosition, overallPosition);

            ClaimResult result = await _fantasyCriticService.ClaimGame(domainRequest);

            bool draftCompleted = await _fantasyCriticService.CompleteDraft(leagueYear.Value);

            var viewModel = new ManagerClaimResultViewModel(result);
            await _hubcontext.Clients.All.SendAsync("RefreshLeagueYear", leagueYear.Value);

            if (draftCompleted)
            {
                await _hubcontext.Clients.All.SendAsync("DraftFinished", leagueYear.Value);
            }

            return(Ok(viewModel));
        }
コード例 #15
0
        public async Task <IActionResult> ManagerClaimGame([FromBody] ClaimGameRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

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

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

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

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

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

            if (!leagueYear.Value.PlayStatus.DraftFinished)
            {
                return(BadRequest("You can't manually manage 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());
            }

            Maybe <MasterGame> masterGame = Maybe <MasterGame> .None;

            if (request.MasterGameID.HasValue)
            {
                masterGame = await _fantasyCriticService.GetMasterGame(request.MasterGameID.Value);
            }

            ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(publisher.Value, request.GameName, request.CounterPick, request.ManagerOverride, masterGame, null, null);

            ClaimResult result = await _fantasyCriticService.ClaimGame(domainRequest);

            var viewModel = new ManagerClaimResultViewModel(result);

            await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value);

            return(Ok(viewModel));
        }
コード例 #16
0
 public PickupBidResultViewModel(ClaimResult domain)
 {
     Success = domain.Success;
     Errors  = domain.Errors.Select(x => x.Error).ToList();
 }
コード例 #17
0
    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);
    }