Ejemplo n.º 1
0
        /// <summary>
        /// Gets all audit actions for role.
        /// </summary>
        /// <param name="roleID">Role ID.</param>
        /// <returns></returns>
        public static RoleAuditActionCollection GetAllAuditActionsForRole(int roleID)
        {
            RoleAuditActionCollection toReturn = new RoleAuditActionCollection();

            toReturn.GetMulti((RoleAuditActionFields.RoleID == roleID));
            return(toReturn);
        }
        /// <summary>
        /// Reads all audit actions for the current selected role and shows these settings in the form
        /// </summary>
        private void ReflectCurrentAuditActions()
        {
            RoleAuditActionCollection roleAuditActions = SecurityGuiHelper.GetAllAuditActionsForRole(_roleID);

            // check the checkboxes in the cblAuditActions list if the value matches an object in the collection
            foreach (RoleAuditActionEntity roleAuditAction in roleAuditActions)
            {
                cblAuditActions.Items.FindByValue(roleAuditAction.AuditActionID.ToString()).Selected = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes the given role from the system.
        /// </summary>
        /// <param name="roleID">ID of role to delete</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteRole(int roleID)
        {
            RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID);

            if (toDelete == null)
            {
                // not found
                return(false);
            }

            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole");

            try
            {
                // remove the role - forum - action right entities
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID);

                // Remove role-audit action entities
                RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
                trans.Add(roleAuditActions);
                roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID);

                // remove Role - systemright entities
                RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection();
                trans.Add(roleSystemRights);
                roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);

                // remove Role - user entities
                RoleUserCollection roleUsers = new RoleUserCollection();
                trans.Add(roleUsers);
                roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID);

                // delete the actual role
                trans.Add(toDelete);
                toDelete.Delete();
                trans.Commit();
                return(true);
            }
            catch
            {
                // error occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the audit actions for role specified. First removes all present rows for the roleid
        /// </summary>
        /// <param name="auditActionIDs">Audit action IDs.</param>
        /// <param name="roleID">Role ID.</param>
        /// <returns>true if the save action succeeded, false otherwise</returns>
        public static bool SaveAuditActionsForRole(List <int> auditActionIDs, int roleID)
        {
            RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "SaveAuditActionsForRole");

            // add this collection to the transaction so all actions executed through this collection will be inside the transaction
            trans.Add(roleAuditActions);

            try
            {
                // first remove the existing rows for the role
                roleAuditActions.DeleteMulti((RoleAuditActionFields.RoleID == roleID));

                // THEN add new ones to the same collection.
                foreach (int auditActionID in auditActionIDs)
                {
                    RoleAuditActionEntity newRoleAuditAction = new RoleAuditActionEntity();
                    newRoleAuditAction.AuditActionID = auditActionID;
                    newRoleAuditAction.RoleID        = roleID;
                    roleAuditActions.Add(newRoleAuditAction);
                }

                // save all new entities
                roleAuditActions.SaveMulti();

                // succeeded, commit transaction
                trans.Commit();
                return(true);
            }
            catch
            {
                // failed, rollback transaction
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves the audit actions for role specified. First removes all present rows for the roleid
        /// </summary>
        /// <param name="auditActionIDs">Audit action IDs.</param>
        /// <param name="roleID">Role ID.</param>
        /// <returns>true if the save action succeeded, false otherwise</returns>
        public static bool SaveAuditActionsForRole(List<int> auditActionIDs, int roleID)
        {
            RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "SaveAuditActionsForRole");

            // add this collection to the transaction so all actions executed through this collection will be inside the transaction
            trans.Add(roleAuditActions);

            try
            {
                // first remove the existing rows for the role
                roleAuditActions.DeleteMulti((RoleAuditActionFields.RoleID == roleID));

                // THEN add new ones to the same collection.
                foreach(int auditActionID in auditActionIDs)
                {
                    RoleAuditActionEntity newRoleAuditAction = new RoleAuditActionEntity();
                    newRoleAuditAction.AuditActionID = auditActionID;
                    newRoleAuditAction.RoleID = roleID;
                    roleAuditActions.Add(newRoleAuditAction);
                }

                // save all new entities
                roleAuditActions.SaveMulti();

                // succeeded, commit transaction
                trans.Commit();
                return true;
            }
            catch
            {
                // failed, rollback transaction
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deletes the given role from the system.
        /// </summary>
        /// <param name="roleID">ID of role to delete</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteRole(int roleID)
        {
            RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID);
            if(toDelete == null)
            {
                // not found
                return false;
            }

            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole");

            try
            {
                // remove the role - forum - action right entities
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID);

                // Remove role-audit action entities
                RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection();
                trans.Add(roleAuditActions);
                roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID);

                // remove Role - systemright entities
                RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection();
                trans.Add(roleSystemRights);
                roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);

                // remove Role - user entities
                RoleUserCollection roleUsers = new RoleUserCollection();
                trans.Add(roleUsers);
                roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID);

                // delete the actual role
                trans.Add(toDelete);
                toDelete.Delete();
                trans.Commit();
                return true;
            }
            catch
            {
                // error occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }