public async Task <IActionResult> GetPublisher(Guid id) { Maybe <Publisher> publisher = await _fantasyCriticService.GetPublisher(id); if (publisher.HasNoValue) { return(NotFound()); } var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); var playersInLeague = await _fantasyCriticService.GetUsersInLeague(publisher.Value.League); bool userIsInLeague = playersInLeague.Any(x => x.UserID == currentUser.UserID); if (!userIsInLeague) { return(Unauthorized()); } bool leaguePlayingYear = publisher.Value.League.Years.Contains(publisher.Value.Year); if (!leaguePlayingYear) { return(BadRequest("League is not playing that year.")); } var requstedPlayerIsInLeague = playersInLeague.Any(x => x.UserID == publisher.Value.User.UserID); if (!requstedPlayerIsInLeague) { return(BadRequest("Requested player is not in requested league.")); } var publisherViewModel = new PublisherViewModel(publisher.Value, _clock); return(Ok(publisherViewModel)); }
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)); }