public async Task <IActionResult> LoginUser([FromBody] UserLoginModel loginModel)
        {
            if (string.IsNullOrEmpty(loginModel.Username) || string.IsNullOrEmpty(loginModel.Password))
            {
                return(BadRequest("Invalid model"));
            }

            var profile = await _userManager.GetByLogin(loginModel.Username);

            if (profile != null)
            {
                var user = _authorizationManager.Authenticate(loginModel, profile);

                if (user != null)
                {
                    var result      = GenerateToken(profile);
                    var tokenString = new JwtSecurityTokenHandler().WriteToken(result);
                    var response    = new TokenResponse
                    {
                        Token        = tokenString,
                        TokenExpires = result.ValidTo,
                        UserId       = user.Id
                    };

                    return(Ok(response));
                }
                return(Unauthorized());
            }

            return(BadRequest("Profile with give login not found"));
        }
        public async Task <IActionResult> LoginUser([FromBody] UserLoginModel loginModel)
        {
            if (string.IsNullOrEmpty(loginModel.Username) || string.IsNullOrEmpty(loginModel.Password))
            {
                return(BadRequest("Invalid model"));
            }

            var profile = await _userManager.GetByLogin(loginModel.Username);

            if (profile != null)
            {
                var user = _authorizationManager.Authenticate(loginModel, profile);

                if (user != null)
                {
                    var result = GenerateToken(profile);
                    return(Ok(new { User = user.Id, Token = result }));
                }
                return(Unauthorized());
            }

            return(NotFound("Profile with give login not found"));
        }