示例#1
0
 public IActionResult GetUser([FromBody] Login model)
 {
     try
     {
         var users = helperClass.GetUser(model);
         if (users == null)
         {
             return(NotFound());
         }
         return(Ok(users));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
示例#2
0
        public APIResponse GetUser([FromBody] LoginModel model)
        {
            APIResponse response = new APIResponse();

            try
            {
                var user = helperClass.GetUser(model);

                if (user != null)
                {
                    var tokenString = helperClass.GenerateJSONWebToken(user);
                    response = new APIResponse
                    {
                        StatusCode = 200,
                        user       = user,
                        Token      = tokenString
                    };
                    return(response);
                }
                else
                {
                    response = new APIResponse
                    {
                        StatusCode = 404,
                        user       = null,
                        Token      = null
                    };
                    return(response);
                }
            }
            catch (Exception e)
            {
                response = new APIResponse
                {
                    StatusCode = 401,
                    user       = null,
                    Token      = null
                };
                return(response);
            }
        }