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)); }
public async Task <ActionResult <MasterGameViewModel> > MasterGame(Guid id) { var masterGame = await _fantasyCriticService.GetMasterGame(id); if (masterGame.HasNoValue) { return(NotFound()); } var viewModel = new MasterGameViewModel(masterGame.Value); return(viewModel); }
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)); }