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)); }
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> 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)); }
public async Task <IActionResult> ManagerDraftGame([FromBody] ManagerDraftGameRequest request) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (!ModelState.IsValid) { 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()); } if (league.Value.LeagueManager.UserID != currentUser.UserID) { return(Forbid()); } var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, publisher.Value.LeagueYear.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 publishersInLeague = await _publisherService.GetPublishersInLeagueForYear(leagueYear.Value); var nextPublisher = _draftService.GetNextDraftPublisher(leagueYear.Value, publishersInLeague); 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 _interLeagueService.GetMasterGame(request.MasterGameID.Value); } var draftPhase = _draftService.GetDraftPhase(leagueYear.Value, publishersInLeague); if (draftPhase.Equals(DraftPhase.StandardGames)) { if (request.CounterPick) { return(BadRequest("Not drafting counterPicks now.")); } } if (draftPhase.Equals(DraftPhase.CounterPicks)) { if (!request.CounterPick) { return(BadRequest("Not drafting standard games now.")); } } var draftStatus = _draftService.GetDraftStatus(leagueYear.Value, publishersInLeague); ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(publisher.Value, request.GameName, request.CounterPick, false, request.ManagerOverride, masterGame, draftStatus.DraftPosition, draftStatus.OverallDraftPosition); var result = await _draftService.DraftGame(domainRequest, true, leagueYear.Value, publishersInLeague); var viewModel = new ManagerClaimResultViewModel(result.Result); await _hubContext.Clients.Group(leagueYear.Value.GetGroupName).SendAsync("RefreshLeagueYear"); if (result.DraftComplete) { await _hubContext.Clients.Group(leagueYear.Value.GetGroupName).SendAsync("DraftFinished"); } 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 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)); }
public async Task <IActionResult> ManagerDraftGame([FromBody] ManagerDraftGameRequest request) { var leagueYearPublisherRecord = await GetExistingLeagueYearAndPublisher(request.PublisherID, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.ActiveDraft); if (leagueYearPublisherRecord.FailedResult is not null) { return(leagueYearPublisherRecord.FailedResult); } var validResult = leagueYearPublisherRecord.ValidResult !; var leagueYear = validResult.LeagueYear; var publisher = validResult.Publisher; var nextPublisher = _draftService.GetNextDraftPublisher(leagueYear); if (nextPublisher is null) { return(BadRequest("There are no spots open to draft.")); } if (!nextPublisher.Equals(publisher)) { return(BadRequest("That publisher is not next up for drafting.")); } MasterGame?masterGame = null; if (request.MasterGameID.HasValue) { masterGame = await _interLeagueService.GetMasterGame(request.MasterGameID.Value); } var draftPhase = _draftService.GetDraftPhase(leagueYear); if (draftPhase.Equals(DraftPhase.StandardGames)) { if (request.CounterPick) { return(BadRequest("Not drafting counterPicks now.")); } } if (draftPhase.Equals(DraftPhase.CounterPicks)) { if (!request.CounterPick) { return(BadRequest("Not drafting standard games now.")); } } var draftStatus = _draftService.GetDraftStatus(draftPhase, leagueYear); bool counterPickedGameIsManualWillNotRelease = PlayerGameExtensions.CounterPickedGameIsManualWillNotRelease(leagueYear, request.CounterPick, masterGame, false); ClaimGameDomainRequest domainRequest = new ClaimGameDomainRequest(leagueYear, publisher, request.GameName, request.CounterPick, counterPickedGameIsManualWillNotRelease, request.ManagerOverride, false, masterGame, draftStatus.DraftPosition, draftStatus.OverallDraftPosition); var result = await _draftService.DraftGame(domainRequest, true); var viewModel = new ManagerClaimResultViewModel(result.Result); await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("RefreshLeagueYear"); if (result.DraftComplete) { await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("DraftFinished"); } return(Ok(viewModel)); }