public async Task <IActionResult> SetDraftOrder([FromBody] DraftOrderRequest 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.PlayStarted) { return(BadRequest()); } var usersInLeague = await _fantasyCriticService.GetUsersInLeague(league.Value); var publishersInLeague = await _fantasyCriticService.GetPublishersInLeagueForYear(leagueYear.Value.League, leagueYear.Value.Year); var readyToSetDraftOrder = _fantasyCriticService.LeagueIsReadyToSetDraftOrder(publishersInLeague, usersInLeague); if (!readyToSetDraftOrder) { return(BadRequest()); } List <KeyValuePair <Publisher, int> > draftPositions = new List <KeyValuePair <Publisher, int> >(); for (var index = 0; index < request.PublisherDraftPositions.Count; index++) { var requestPublisher = request.PublisherDraftPositions[index]; var publisher = publishersInLeague.SingleOrDefault(x => x.PublisherID == requestPublisher); if (publisher is null) { return(BadRequest()); } draftPositions.Add(new KeyValuePair <Publisher, int>(publisher, index + 1)); } var result = await _fantasyCriticService.SetDraftOrder(leagueYear.Value, draftPositions); if (result.IsFailure) { return(BadRequest(result.Error)); } return(Ok()); }