Example #1
0
        public IHttpActionResult Login([FromBody] UserLoginRequest user)
        {
            try
            {
                if (user == null || user.RequiredFieldsAreNullOrBlank)
                {
                    return(BadRequest("Some or all of the data required for user registration is blank or missing. Please try again."));
                }
                var result = _users.Login(user);

                if (result.Status == RepositoryActionStatus.Updated)
                {
                    var authenticatedUser = _userFactory.CreateAuthenticatedUser(result.Entity);
                    var response          = _responseFactory.CreateResponse(authenticatedUser);
                    return(Ok(response));
                }
                else if (result.Status == RepositoryActionStatus.NotFound)
                {
                    return(NotFound());                    //user was not found or passwords did not match
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }
        }