public async Task <IActionResult> NewPassword([FromBody] PasswordRegister password) { if (password == null) { return(BadRequest("Non optional fields cannot be empty.")); } var user = await _repo.GetUser(password.UserId); if (user == null) { ModelState.AddModelError("UserId", "User does not exists."); } if (await _repo.PasswordExists(password.Name, password.UserId)) { ModelState.AddModelError("Name", "Password name already exists in the database."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newPassword = _mapper.Map <Password>(password); newPassword.Created = DateTime.Now; newPassword.Updated = DateTime.Now; await _repo.AddPassword(newPassword, user.UserKey); if (await _repo.SaveAll()) { return(StatusCode(201)); } return(BadRequest()); }