Ejemplo n.º 1
0
        public async Task <IActionResult> LeaveLeague(int id)
        {
            int loggedUserId;

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

            var userInLeague = await leagueRepository.GetUserInLeague(loggedUserId, id);

            if (userInLeague == null)
            {
                return(BadRequest("You are not a member of this league."));
            }

            leagueRepository.DeleteUserInLeague(userInLeague);

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

            return(BadRequest("Could not leave league"));
        }