public async Task <IActionResult> DeleteUser([FromQuery] string userName) { var response = await _userService.DeleteUser(userName); if (response != null) { return(Ok(response)); } return(BadRequest()); }
public async Task <IActionResult> DeleteUser(Guid id, Guid UserId) { ApiResponse <string> response = new ApiResponse <string>(); try { if (!response.Errors.Any()) { var userFromRepo = await _userSrv.GetUser(id); if (userFromRepo == null) { response.Code = ApiResponseCodes.NOT_FOUND; response.Description = $"Invalid User Id"; } var currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (currentUserId != userFromRepo.Email) { response.Code = ApiResponseCodes.UNAUTHORIZED; response.Description = $"UnAuthorized"; } (List <ValidationResult> Result, AppUser User)errorResult = await _userSrv.DeleteUser(UserId); if (errorResult.Result.Any()) { response.Description = errorResult.Result.FirstOrDefault().ErrorMessage; response.Code = ApiResponseCodes.ERROR; } else { response.Code = ApiResponseCodes.OK; response.Description = $"User Deleted Successfully."; } } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok(response)); }