public IActionResult Delete(int id) { var model = new UserDeleteModel() { Id = id }; var deleteResult = false; var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:63868/api/user/delete"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "DELETE"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var json = JsonConvert.SerializeObject(model); streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); deleteResult = bool.Parse(result); } return(RedirectToAction("Index", "User")); }
public IActionResult DeleteUser(UserDeleteModel model) { if (ModelState.IsValid) { using (var uow = _identityDataService.StartUnitOfWork()) { var user = uow.UserRepository.FindByNormalizedEmail(model.Email.ToLower(CultureInfo.InvariantCulture)); var roles = uow.UserRoleRepository.FindByUser(user); var userRoles = roles.Select(r => uow.UserRoleRepository.FindByUserIdAndRoleId(user.Id, r)).ToList(); var userLogins = uow.LoginRepository.FindByUserId(user.Identifier); foreach (var userRole in userRoles) { uow.UserRoleRepository.Delete(userRole); } foreach (var userLogin in userLogins) { uow.LoginRepository.Delete(userLogin); } uow.UserRepository.Delete(user); uow.Commit(); return(RedirectToAction(nameof(ManageUsers))); } } return(View(model)); }
public ActionResult DeleteUser([FromBody] UserDeleteModel model) { var data = new UserModel() { UserId = model.UserId }; userService.DeleteUser(data); return(Ok()); }
public IActionResult Delete(UserDeleteModel userDeleteModel) { var result = _userDataAccess.DeleteAsync(userDeleteModel.Id).Result; if (result == null) { return(BadRequest("Not found")); } return(Ok(new { result })); }
public async Task DeleteAsync(UserDeleteRequest rq) { UserDeleteModel dto = rq.User; ApplicationUser user = await _userMgr.FindByIdAsync(dto.Id); IdentityResult deleteResult = await _userMgr.DeleteAsync(user); if (!deleteResult.Succeeded) { throw new InvalidOperationException(string.Join('\n', deleteResult.Errors.Select(e => $"Error code: {e.Code}. Message: {e.Description}"))); } }
public IHttpActionResult Delete(UserDeleteModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } User userToDelete = this.context.Users.Find(model.Id); if (userToDelete == null) { return(this.BadRequest("Cannot find user with id: " + model.Id)); } this.context.Users.Remove(userToDelete); this.context.SaveChanges(); return(this.Ok()); }