Example #1
0
        public async Task <ActionResult <User> > GetUserByAccessToken([FromBody] string accessToken)
        {
            try
            {
                string userID = GenerateToken.GetUserIdFromAccessToken(accessToken, jwtsettings);

                //return await _context.Users.Include(u => u.Role)
                //                      .Where(u => u.UserId == Convert.ToInt32(userId)).FirstOrDefaultAsync();

                var user = await userRepository.GetUserByID(Convert.ToInt32(userID));

                if (user != null)
                {
                    return(Ok(user));
                }
                else
                {
                    return(NotFound("User not found"));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }