public async Task <IActionResult> UndoLastDraftAction([FromBody] UndoLastDraftActionRequest request) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (!ModelState.IsValid) { return(BadRequest()); } var league = await _fantasyCriticService.GetLeagueByID(request.LeagueID); if (league.HasNoValue) { return(BadRequest()); } if (league.Value.LeagueManager.UserID != currentUser.UserID) { return(Forbid()); } var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, request.Year); if (leagueYear.HasNoValue) { return(BadRequest()); } if (!leagueYear.Value.PlayStatus.Equals(PlayStatus.DraftPaused)) { return(BadRequest("Can only undo when the draft is paused.")); } var publishers = await _publisherService.GetPublishersInLeagueForYear(leagueYear.Value); bool hasGames = publishers.SelectMany(x => x.PublisherGames).Any(); if (!hasGames) { return(BadRequest("Can't undo a drafted game if no games have been drafted.")); } await _draftService.UndoLastDraftAction(leagueYear.Value, publishers); await _hubContext.Clients.Group(leagueYear.Value.GetGroupName).SendAsync("RefreshLeagueYear"); return(Ok()); }
public async Task <IActionResult> UndoLastDraftAction([FromBody] UndoLastDraftActionRequest request) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (!ModelState.IsValid) { return(BadRequest()); } var league = await _fantasyCriticService.GetLeagueByID(request.LeagueID); if (league.HasNoValue) { return(BadRequest()); } if (league.Value.LeagueManager.UserID != currentUser.UserID) { return(Unauthorized()); } var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, request.Year); if (leagueYear.HasNoValue) { return(BadRequest()); } if (!leagueYear.Value.PlayStatus.Equals(PlayStatus.DraftPaused)) { return(BadRequest("Can only undo when the draft is paused.")); } await _fantasyCriticService.UndoLastDraftAction(leagueYear.Value); await _hubcontext.Clients.All.SendAsync("RefreshLeagueYear", leagueYear.Value); return(Ok()); }
public async Task <IActionResult> UndoLastDraftAction([FromBody] UndoLastDraftActionRequest request) { var leagueYearRecord = await GetExistingLeagueYear(request.LeagueID, request.Year, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.DraftPaused); if (leagueYearRecord.FailedResult is not null) { return(leagueYearRecord.FailedResult); } var validResult = leagueYearRecord.ValidResult !; var leagueYear = validResult.LeagueYear; bool hasGames = leagueYear.Publishers.Any(x => x.PublisherGames.Any()); if (!hasGames) { return(BadRequest("Can't undo a drafted game if no games have been drafted.")); } await _draftService.UndoLastDraftAction(leagueYear); await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("RefreshLeagueYear"); return(Ok()); }