void CreateRoles(string nodeID)
        {
            Role role;

            //Create Administrator role
            role = new Role() { Name = "Administrator", Description = "Administrator Role", NodeID = nodeID, CreatedBy = ((App)Application.Current).Principal.Identity.Name, UpdatedBy = ((App)Application.Current).Principal.Identity.Name };
            CommonFunctions.SaveRole(null, role, true);

            //Create Editor role
            role = new Role() { Name = "Editor", Description = "Editor Role", NodeID = nodeID, CreatedBy = ((App)Application.Current).Principal.Identity.Name, UpdatedBy = ((App)Application.Current).Principal.Identity.Name };
            CommonFunctions.SaveRole(null, role, true);

            //Create Viewer role
            role = new Role() { Name = "Viewer", Description = "Viewer Role", NodeID = nodeID, CreatedBy = ((App)Application.Current).Principal.Identity.Name, UpdatedBy = ((App)Application.Current).Principal.Identity.Name };
            CommonFunctions.SaveRole(null, role, true);
        }
 void ListBoxRoles_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (ListBoxRoles.SelectedIndex >= 0)
     {
         m_selectedRole = (Role)ListBoxRoles.SelectedItem;
         ListBoxCurrentRoleUsers.ItemsSource = m_selectedRole.CurrentRoleUsers = CommonFunctions.GetCurrentRoleUsers(null, m_selectedRole.ID);
         ListBoxCurrentRoleGroups.ItemsSource = m_selectedRole.CurrentRoleGroups = CommonFunctions.GetCurrentRoleGroups(null, m_selectedRole.ID);
         ListBoxPossibleRoleUsers.ItemsSource = m_selectedRole.PossibleRoleUsers = CommonFunctions.GetPossibleRoleUsers(null, m_selectedRole.ID);
         ListBoxPossibleRoleGroups.ItemsSource = m_selectedRole.PossibleRoleGroups = CommonFunctions.GetPossibleRoleGroups(null, m_selectedRole.ID);
         GridManageRoles.DataContext = m_selectedRole;
         m_editRoleMode = true;
         ChangeRoleUserAndGroupsVisualization();
     }
     else
         ClearRoleInformation();
 }
 void ClearRoleInformation()
 {
     m_selectedRole = null;
     GridManageRoles.DataContext = new Role();
     m_editRoleMode = false;
     ListBoxRoles.SelectedIndex = -1;
     TextBlockRoleUsersMessage.Visibility = Visibility.Collapsed;
     ChangeRoleUserAndGroupsVisualization();
 }
Exemple #4
0
        public static string SaveRole(DataConnection connection, Role role, bool isNew)
        {
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }
                IDbCommand command = connection.Connection.CreateCommand();
                command.CommandType = CommandType.Text;

                if (isNew)
                    command.CommandText = "Insert Into ApplicationRole (Name, Description, NodeID, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values (@name, @description, @nodeID, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update ApplicationRole Set Name = @name, Description = @description, NodeID = @nodeID, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

                command.Parameters.Add(AddWithValue(command, "@name", role.Name));
                command.Parameters.Add(AddWithValue(command, "@description", role.Description));
                if (command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB"))
                    command.Parameters.Add(AddWithValue(command, "@nodeID", "{" + role.NodeID + "}"));
                else
                    command.Parameters.Add(AddWithValue(command, "@nodeID", role.NodeID));
                command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser));
                command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));

                if (isNew)
                {
                    command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser));
                    command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));
                }
                else
                    command.Parameters.Add(AddWithValue(command, "@id", role.ID));

                command.ExecuteNonQuery();

                return "Role Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }