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)); }
public async Task <IActionResult> ManagerClaimGame([FromBody] ClaimGameRequest 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 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 _interLeagueService.GetMasterGame(request.MasterGameID.Value); } ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(publisher.Value, request.GameName, request.CounterPick, request.ManagerOverride, false, masterGame, null, null); var publishersInLeague = await _publisherService.GetPublishersInLeagueForYear(leagueYear.Value); ClaimResult result = await _gameAcquisitionService.ClaimGame(domainRequest, true, false, publishersInLeague); var viewModel = new ManagerClaimResultViewModel(result); await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value); return(Ok(viewModel)); }