Beispiel #1
0
        public IActionResult CreateUser([FromBody] UserLogin userLogin)
        {
            try
            {
                if (userLogin.Equals(null))
                {
                    _logger.LogError("UserLogin object sent from client is null.");
                    return(BadRequest("UserLogin object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid UserLogin object sent from client.");
                    return(BadRequest("Invalid model object"));
                }


                _repository.UserLogin.CreateUserLogin(userLogin);

                return(Ok(userLogin));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CreateUserLogin action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Beispiel #2
0
        public IActionResult UpdateUserLogin(string username, [FromBody] UserLogin userLogin)
        {
            try
            {
                if (userLogin.Equals(null))
                {
                    _logger.LogError("UserLogin object sent from client is null.");
                    return(BadRequest("UserLogin object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid UserLogin object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                var dbUserLogin = _repository.UserLogin.GetUserLoginByUsername(username);
                if (dbUserLogin.Equals(null))
                {
                    _logger.LogError($"User with id: {username}, hasn't been found in db.");
                    return(NotFound());
                }

                _repository.UserLogin.UpdateUserLogin(dbUserLogin, userLogin);

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateUserLogin action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }