public ActionResult DeleteUser(DeleteUserVM deletedUser) { if (ModelState.IsValid) { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore); var currentUser = manager.FindByEmail(deletedUser.Email); OneListCAEntities context = new OneListCAEntities(); if (currentUser != null) { var user = context.AspNetUsers.Find(currentUser.Id); var userProfile = context.Users.Find(currentUser.Id); context.AspNetUsers.Remove(user); context.Users.Remove(userProfile); context.SaveChanges(); ViewBag.Success = "User has been deleted successfully!"; } else { ViewBag.Fail = "User not found!"; } } return(View()); }
public ActionResult UnbanUser(DeleteUserVM deletedUser) { if (ModelState.IsValid) { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore); var currentUser = manager.FindByEmail(deletedUser.Email); OneListCAEntities context = new OneListCAEntities(); if (currentUser != null) { var user = context.AspNetUsers.Find(currentUser.Id); if (user.PhoneNumberConfirmed == true) { user.PhoneNumberConfirmed = false; context.SaveChanges(); SendGrid.sendUnbanUserEmail(currentUser.Email, currentUser.UserName); ViewBag.Success = "User has been unbanned successfully!"; } else { ViewBag.Fail = "This user is not banned!"; } } else { ViewBag.Fail = "User not found!"; } } return(View()); }
public async Task <IActionResult> DeleteUser(DeleteUserVM user) { try { if (string.IsNullOrWhiteSpace(user.UserId) || string.IsNullOrWhiteSpace(user.UserToken)) { throw new Exception("Something went wrong."); } var result = await _service.DeleteUser(user); if (string.IsNullOrWhiteSpace(result.Failed)) { return(Ok(result.Success)); } else if (result.Failed.Contains("found")) { return(NotFound(result.Failed)); } else { throw new Exception(result.Failed); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult DeleteUser(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DeleteUserVM DeletedUser = new DeleteUserVM(DataBase.UserDataBase.Find(id)); if (DeletedUser == null) { return(HttpNotFound()); } return(View(DeletedUser)); }
public OperationResult Delete(DeleteUserVM command) { OperationResult result = new OperationResult(); var user = _userRepository.Get(command.Id); if (user == null) { return(result.Failed(ValidateMessage.IsExist)); } user.Delete(); _userRepository.SaveChanges(); return(result.Succeeded()); }
public async Task <IActionResult> DeleteUser(Guid userId, DeleteUserVM vm) { User user = lists.GetUser(userId); if (user == null) { Message("Can't find user requested"); return(RedirectToRoute(Names.AdminIndex)); } await lists.RemoveUser(user); Message("Deleted user {0}", vm.Name); return(RedirectToRoute(Names.AdminIndex)); }
public async Task <ResultVM> DeleteUser(DeleteUserVM userVM) { try { if (string.IsNullOrWhiteSpace(userVM.UserId) || string.IsNullOrWhiteSpace(userVM.UserToken)) { throw new Exception("Something went wrong."); } var user = await _userManager.FindByIdAsync(userVM.UserId); if (user == null) { throw new Exception("Cannot find the active user."); } var userResult = await _userManager.VerifyUserTokenAsync(user, "Default", "authentication-backend", userVM.UserToken); if (!userResult) { throw new Exception("Cannot verify the active user"); } var result = await _userManager.DeleteAsync(user); if (result.Succeeded) { return(new ResultVM() { Success = "User was successfully deleted." }); } else { throw new Exception("Something went wrong!"); } } catch (Exception ex) { return(new ResultVM() { Failed = ex.Message }); } }
public ActionResult Delete(int?id) { if (Session["UserName"] == null) { return(RedirectToAction("Login", "Authentication")); } else { if (ModelState.IsValidField("Email") && ModelState.IsValidField("Imię") && ModelState.IsValidField("Nazwisko") && ModelState.IsValidField("Wiek")) { string currentUser = Session["UserId"].ToString(); int uid = Int32.Parse(currentUser); List <User> userList = db.GetUserList(); User user = userList.Where(a => a.UserId == uid).Single(); DeleteUserVM deleteVM = new DeleteUserVM(); deleteVM.user = user; return(View("Delete", deleteVM)); } return(View()); } }
public IActionResult OnPostDelete(DeleteUserVM command) { var result = _userApplication.Delete(command); return(new JsonResult(result)); }