public async Task <IActionResult> CreateInviteLink([FromBody] CreateInviteLinkRequest 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()); } IReadOnlyList <LeagueInviteLink> activeLinks = await _leagueMemberService.GetActiveInviteLinks(league.Value); if (activeLinks.Count >= 2) { return(BadRequest("You can't have more than 2 invite links active.")); } await _leagueMemberService.CreateInviteLink(league.Value); return(Ok()); }
public async Task <IActionResult> CreateInviteLink([FromBody] CreateInviteLinkRequest request) { var leagueRecord = await GetExistingLeague(request.LeagueID, RequiredRelationship.LeagueManager); if (leagueRecord.FailedResult is not null) { return(leagueRecord.FailedResult); } var validResult = leagueRecord.ValidResult !; var league = validResult.League; IReadOnlyList <LeagueInviteLink> activeLinks = await _leagueMemberService.GetActiveInviteLinks(league); if (activeLinks.Count >= 2) { return(BadRequest("You can't have more than 2 invite links active.")); } await _leagueMemberService.CreateInviteLink(league); return(Ok()); }