public async Task <ActionResult> CreateNurseAsync([FromBody] NurseCreateModel nurseCM) { MyUser user = null; try { //asp.net user_ create account user = nurseCM.Adapt <MyUser>(); user.IsActive = false; user.DateCreated = DateTime.Now; user.UserName = nurseCM.HisCode; var currentUser = await _userManager.CreateAsync(user, DefaultPassword.PasswordNurse); if (currentUser.Succeeded) { if (!(await _userManager.AddToRoleAsync(user, nameof(UserRoles.Nurse))).Succeeded) { _userManager.DeleteAsync(user); return(BadRequest(user + "\n Add role fail!")); } //create nurse basic Nurse nurse = nurseCM.Adapt <Nurse>(); nurse.Id = user.Id; _nurseService.CreateNurse(nurse, (await _userManager.GetUserAsync(User)).UserName); } else { if (user != null) { _userManager.DeleteAsync(user); } return(BadRequest(currentUser.Errors)); } _nurseService.Save(); return(StatusCode(201)); } catch (Exception e) { if (user != null) { _userManager.DeleteAsync(user); } return(BadRequest(e.Message)); } }