internal static void DeleteUser() { Console.WriteLine("Input user Id to delete"); string input = Console.ReadLine(); if (!UserIds.ContainsKey(int.Parse(input))) { Console.WriteLine("Wrong input!"); } Guid deleteGuid = UserIds[int.Parse(input)]; try { User deleteUser = usersmanager.GetUserId(deleteGuid); if (usersmanager.DeleteUser(deleteUser)) { Console.WriteLine($"User with Id {input} deleted"); } else { Console.WriteLine("Delete unsuccessfully"); } } catch { Console.WriteLine("Wrong Id of user"); return; } }
protected void grdUsers_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e) { string id = grdUsers.DataKeys[e.RowIndex].Values["Id"].ToString(); UsersManager.DeleteUser(id); grdUsers.DataBind(); e.Cancel = true; }
public void TestUserIntegration() { using (UsersManager manager = new UsersManager()) { var user = manager.RegisterUser("test", "*****@*****.**", "test"); Assert.IsTrue(manager.TryLogin("test", "test", out user)); manager.DeleteUser(user); } }
private void OnDeleteUserCommandExecuted(object parameter) { var user = selectedUser; UsersManager.DeleteUser(user); Users.Remove(user); OnPropertyChanged(nameof(SelectedUser)); }
private void deleteSelectedUser_Click(object sender, EventArgs e) { if ((this.usesList.SelectedItem as User).Roles.Contains("admin")) { Util.ShowErrorMessage("不能删除'管理员'用户!"); return; } userManager.DeleteUser((this.usesList.SelectedItem as User).Name); this.usersIsDirty = true; }
public async Task <ActionResult> DeleteUser(int id) { if (_userManager.DeleteUser(id)) { return(Ok()); } else { return(BadRequest()); } }
protected void btnDelete_Click(object sender, EventArgs e) { if (txtUserId.Text.ToString().Trim() != String.Empty) { Users usr = UsersManager.getUser(txtUserId.Text.ToString().ToUpper()); if (usr != null) { UsersManager.DeleteUser(usr); lblTranStatus.Visible = true; lblTranStatus.Text = "User deleted successfully!!"; lblTranStatus.ForeColor = System.Drawing.Color.Green; } } }
public void DeleteUser(string userId) { int id = 0; Int32.TryParse(userId, out id); UserDT user = UsersManager.GetUser(id); ApplicationUser toDelte = UserManager.FindById(user.AspNetId); bool result = System.Web.Security.Membership.DeleteUser(toDelte.UserName); if (result) { UsersManager.DeleteUser(id); } }
protected void Page_Load(object sender, EventArgs e) { NameValueCollection f = Request.Form; if (!AppCode.GetSesIsAdmin(Session)) { Response.Redirect("."); } else { using (UsersManager um = new UsersManager()) { users = um.GetAllUsers(); if (!um.IsUserAdmin(AppCode.GetSesID(Session))) { Response.Redirect("."); } } lv.DataSource = users; lv.DataBind(); } if (f["upd"] != null || f["del"] != null) { if (f["upd"] != null) { id = int.Parse(f["upd"].ToString()); string sid = id.ToString(); username = f["username" + sid]; pass = f["password" + sid]; email = f["email" + sid]; active = f["active" + sid] != null; admin = f["admin" + sid] != null; if (pass.Length <= 5) { mainErr = "הסיסמה חייבת להיות בת 6 ספרות לפחות. "; return; } if (username.Contains(" ")) { mainErr = "שם המשתמש לא יכול להכיל רווחים. "; return; } using (UsersManager um = new UsersManager()) { user = um.GetUserFromID(id); um.UpdateUser(new User(user.id, username, pass, email, user.name, user.gender, user.dj, user.tr, user.am, user.dh, user.bio, active, admin)); users = um.GetAllUsers(); lv.DataBind(); Response.Redirect(Request.RawUrl); } } if (f["del"] != null) { id = int.Parse(f["del"]); using (UsersManager um = new UsersManager()) { um.DeleteUser(id); users = um.GetAllUsers(); lv.DataBind(); Response.Redirect(Request.RawUrl); } } } }
private static void SelectOptionByUser() { while (true) { Console.WriteLine("Please, select some action"); Console.WriteLine("1: Add User"); Console.WriteLine("2: Delete User"); Console.WriteLine("3: Show User's info"); Console.WriteLine("4: Show User's list"); Console.WriteLine("5: Add awards"); Console.WriteLine("6: Exit"); var input = Console.ReadLine(); if (uint.TryParse(input, out uint selectedOptions) && selectedOptions > 0 && selectedOptions < 7) { int usersId = -1; switch (selectedOptions) { case 1: Console.WriteLine("Enter user's Name. Name must not contain spaces"); string usersName = Console.ReadLine(); Console.WriteLine("Enter user's date of birth in the format YYYY,MM,DD"); DateTime dateOfBirth = new DateTime(1995, 01, 01); DateTime.TryParse(Console.ReadLine(), out dateOfBirth); UsersManager.CreateNewUser(usersName, dateOfBirth); break; case 2: Console.WriteLine("Enter user's id. if you do not remember id, you can look at the list."); int.TryParse(Console.ReadLine(), out usersId); if (UsersManager.DeleteUser(usersId)) { Console.WriteLine("True"); } else { Console.WriteLine("False"); } break; case 3: Console.WriteLine("Enter user's id. if you do not remember id, you can look at the list"); int.TryParse(Console.ReadLine(), out usersId); Console.WriteLine(UsersManager.ShowUser(usersId)); break; case 4: Console.WriteLine(UsersManager.ShowUsersList()); break; case 5: Console.WriteLine("Enter user's id. if you do not remember id, you can look at the list"); int.TryParse(Console.ReadLine(), out usersId); Console.WriteLine("Enter user's award"); string usersaward = Console.ReadLine(); if (UsersManager.AppendAwards(usersId, usersaward)) { Console.WriteLine("True"); } else { Console.WriteLine("False"); } break; case 6: UsersManager.DataSynchronization(); return; } } } }
static void Run() { for (; ;) { Console.WriteLine("-----------------------------------" + Environment.NewLine + "Please choose option:" + Environment.NewLine + "\t 1: Add user" + Environment.NewLine + "\t 2: Delete user" + Environment.NewLine + "\t 3: See all users" + Environment.NewLine + "\t 4: Add award" + Environment.NewLine + "\t 5: Add award to user" + Environment.NewLine + "\t 6: Delete award" + Environment.NewLine + "\t 7: See all awards" + Environment.NewLine + "-----------------------------------"); if (uint.TryParse(Console.ReadLine(), out uint option) && option > 0 && option < 8) { UsersManager manager = new UsersManager(); AwardsManager Manager = new AwardsManager(); Guid UserId; Guid AwardId; switch (option) { case 1: { Console.WriteLine("Enter user name"); var Name = Console.ReadLine(); Console.WriteLine("Enter date of birth"); DateTime DateOfBirth; if (!DateTime.TryParse(Console.ReadLine(), out DateOfBirth)) { Console.WriteLine("Error!!! Wrong date format"); } else if (DateOfBirth > DateTime.Now) { Console.WriteLine("Error!!! Wrong date"); } else { Userss newUser = new Userss(Name, DateOfBirth); manager.AddUser(newUser); } break; } case 2: { Console.WriteLine("Enter user id"); if (!Guid.TryParse(Console.ReadLine(), out UserId)) { Console.WriteLine("Error!!! Wrong id format"); } else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId)) { Console.WriteLine("Error!!! This user does not exist"); } else { manager.DeleteUser(UserId); } break; } case 3: { foreach (Userss user in manager.GetAllUsers()) { Console.WriteLine(user); } break; } case 4: { Console.WriteLine("Enter award name"); var Name = Console.ReadLine(); Awards award = new Awards(Name); Manager.AddAward(award); break; } case 5: { Console.WriteLine("Enter user Id"); if (!Guid.TryParse(Console.ReadLine(), out UserId)) { Console.WriteLine("Error!!! Wrong id format"); } else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId)) { Console.WriteLine("Error!!! This user does not exist"); } else { Console.WriteLine("Enter award Id"); if (!Guid.TryParse(Console.ReadLine(), out AwardId)) { Console.WriteLine("Error!!! Wrong id format"); } else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId)) { Console.WriteLine("Error!!! This award does not exist"); } else { manager.AddAwardToUser(UserId, AwardId); } } break; } case 6: { Console.WriteLine("Enter award Id"); if (!Guid.TryParse(Console.ReadLine(), out AwardId)) { Console.WriteLine("Error!!! Wrong id format"); } else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId)) { Console.WriteLine("Error!!! This award does not exist"); } else { Manager.DeleteAward(AwardId); } break; } case 7: { foreach (Awards award in Manager.GetAllAwards()) { Console.WriteLine(award); } break; } default: { Console.WriteLine("Unknown command!"); break; } } } else { Console.WriteLine("Error!!! Wrong option"); } } }