public async Task <IActionResult> ResetDraft([FromBody] ResetDraftRequest 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.NotStartedDraft) || leagueYear.Value.PlayStatus.Equals(PlayStatus.DraftFinal)) { return(BadRequest()); } var supportedYear = (await _interLeagueService.GetSupportedYears()).SingleOrDefault(x => x.Year == request.Year); if (supportedYear is null) { return(BadRequest()); } await _draftService.ResetDraft(leagueYear.Value); await _hubContext.Clients.Group(leagueYear.Value.GetGroupName).SendAsync("RefreshLeagueYear"); return(Ok()); }
public async Task <IActionResult> ResetDraft([FromBody] ResetDraftRequest request) { var leagueYearRecord = await GetExistingLeagueYear(request.LeagueID, request.Year, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.DuringDraft); if (leagueYearRecord.FailedResult is not null) { return(leagueYearRecord.FailedResult); } var validResult = leagueYearRecord.ValidResult !; var leagueYear = validResult.LeagueYear; await _draftService.ResetDraft(leagueYear); await _hubContext.Clients.Group(leagueYear.GetGroupName).SendAsync("RefreshLeagueYear"); return(Ok()); }