public async Task <IActionResult> JoinLeague(int id)
        {
            int loggedUserId;

            Int32.TryParse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value, out loggedUserId);

            if (await leagueRepository.CountUserLeagues(loggedUserId) >= 5)
            {
                return(BadRequest("You cannot be a member of more than 5 leagues."));
            }

            if (await leagueRepository.Member(id, loggedUserId))
            {
                return(BadRequest("You are already a member of this league."));
            }

            var league = await leagueRepository.GetLeague(id);

            if (league == null)
            {
                return(BadRequest("League not found."));
            }

            var userInLeague = new UserInLeague
            {
                User   = await userRepository.GetUser(loggedUserId),
                League = league
            };

            leagueRepository.Join(userInLeague);

            if (await dataContext.Commit())
            {
                return(Ok());
            }

            return(BadRequest("Something went wrong. Try again later."));
        }