public async Task <IActionResult> StartDraft([FromBody] StartDraftRequest 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.NotStartedDraft)) { return(BadRequest()); } var publishersInLeague = await _fantasyCriticService.GetPublishersInLeagueForYear(leagueYear.Value.League, leagueYear.Value.Year); var supportedYear = (await _fantasyCriticService.GetSupportedYears()).SingleOrDefault(x => x.Year == request.Year); if (supportedYear is null) { return(BadRequest()); } var usersInLeague = await _fantasyCriticService.GetUsersInLeague(league.Value); bool readyToPlay = _fantasyCriticService.LeagueIsReadyToPlay(supportedYear, publishersInLeague, usersInLeague); if (!readyToPlay) { return(BadRequest()); } await _fantasyCriticService.StartDraft(leagueYear.Value); await _hubcontext.Clients.All.SendAsync("RefreshLeagueYear", leagueYear.Value); return(Ok()); }