Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private void action3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ra = new RoleAction
            {
                ActionType = 3,
                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 from principal(s)...",
              (bw, evt) =>
              {
                  var action = (RoleAction)evt.Argument;

                  var rManager = new RoleManager(Service);
                  rManager.RemoveExistingRolesFromPrincipals(action.Principals);

                  bw.ReportProgress(0, "Adding roles to principals ({0} %)...");

                  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);
        }