public async Task <IActionResult> ManagerAssociateGame([FromBody] AssociateGameRequest 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 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 _fantasyCriticService.GetMasterGame(request.MasterGameID); if (masterGame.HasNoValue) { return(BadRequest()); } AssociateGameDomainRequest domainRequest = new AssociateGameDomainRequest(publisher.Value, publisherGame, masterGame.Value, request.ManagerOverride); ClaimResult result = await _fantasyCriticService.AssociateGame(domainRequest); var viewModel = new ManagerClaimResultViewModel(result); await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value); return(Ok(viewModel)); }