public async Task Should_Create_User() { var model = new CreateUserViewModel { Email = "*****@*****.**", FirstName = "test", LastName = "test" }; var user = await _userApiViewModelService.CreateUser(model); var getUser = _userManager.Object.Users.FirstOrDefault(u => u.Id == user.Id); Assert.NotNull(getUser); }
public async Task <object> AddEdit([FromBody] CreateUserViewModel model) { var apiUserId = User.ApiGetUserId(); model.ProcessedById = apiUserId; if (ModelState.IsValid) { var getUser = await _userManager.FindByEmailAsync(model.Email); if (getUser != null && getUser.Id != model.Id) { ModelState.AddModelError("", _localizer["UserExistWithSameEmail"]); return(BadRequest(Errors.GetErrorList(ModelState))); } var isAdmin = await _userService.UserInRole(apiUserId, "Admin"); if (!isAdmin && apiUserId != model.Id) { ModelState.AddModelError("", _localizer["AdminUserError"]); return(BadRequest(Errors.GetErrorList(ModelState))); } if (model.Id != null) { var user = await _userViewModelService.EditUser(model, isAdmin); return(Ok(await _userViewModelService.ToViewModel(user))); } if (isAdmin) { model.CreatedAt = DateTime.UtcNow; var user = await _userViewModelService.CreateUser(model); await SendGeneratePasswordLink(user); return(Ok(await _userViewModelService.ToViewModel(user))); } } return(BadRequest(Errors.GetErrorList(ModelState))); }