示例#1
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();
            }
        }
示例#2
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();
            }
        }
示例#3
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();
            }
        }
示例#4
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();
            }
        }