private void action1ToolStripMenuItem_Click(object sender, EventArgs e) { var ra = new RoleAction { ActionType = 1, Roles = roleSelector1.SelectedRoles, Principals = principalSelector1.SelectedItems }; WorkAsync("Adding roles to principal(s)...", (bw, evt) => { var action = (RoleAction)evt.Argument; var rManager = new RoleManager(Service); rManager.AddRolesToPrincipals(action.Roles, action.Principals, allRoles, bw); }, evt => { if (evt.Error != null) { MessageBox.Show(this, "An error occured: " + evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, evt => SetWorkingMessage(string.Format(evt.UserState.ToString(), evt.ProgressPercentage)), ra); }
private void action2ToolStripMenuItem_Click(object sender, EventArgs e) { var ra = new RoleAction { ActionType = 2, Roles = roleSelector1.SelectedRoles, Principals = principalSelector1.SelectedItems }; if (ra.Principals.Any(p => p.Id == currentUserId)) { MessageBox.Show(this, "You can't remove roles from your own profile. Your profile will be removed from the principals list", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); ra.Principals.Remove(ra.Principals.First(r => r.Id == currentUserId)); } WorkAsync("Removing roles to principal(s)...", (bw, evt) => { var action = (RoleAction) evt.Argument; var rManager = new RoleManager(Service); rManager.RemoveRolesFromPrincipals(action.Roles, action.Principals, allRoles, bw); }, evt => { if (evt.Error != null) { MessageBox.Show(this, "An error occured: " + evt.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, evt => SetWorkingMessage(string.Format(evt.UserState.ToString(), evt.ProgressPercentage)), ra); }