public async Task <IActionResult> Update(string id, [FromBody] EmpUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _userService.Update(id, request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ApiResult <bool> > Update(string id, EmpUpdateRequest request) { if (await _userManager.Users.AnyAsync(x => x.Email.Equals(request.Email) && x.Id != id)) { return(new ApiErrorResult <bool>("Email existed")); } var user = await _userManager.FindByIdAsync(id.ToString()); user.DateCreated = request.DateCreated; user.Email = request.Email; user.Name = request.Name; user.PhoneNumber = request.PhoneNumber; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(new ApiSuccessResult <bool>()); } return(new ApiErrorResult <bool>("Update user failed")); }