Exemple #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();
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves the given set of actionrights as the set of forum action rights for the given forum / role combination.
        /// It first removes all current action rights for that combination.
        /// </summary>
        /// <param name="actionRightIDs">List of actionrights to set of this role</param>
        /// <param name="roleID">Role to use</param>
        /// <param name="forumID">Forum to use</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool SaveForumActionRightsForForumRole(List <int> actionRightIDs, int roleID, int forumID)
        {
            ForumRoleForumActionRightCollection forumRightsPerRole = new ForumRoleForumActionRightCollection();
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "SaveForumActionRights");

            // add this collection to the transaction so all actions executed through this collection will be inside the transaction
            trans.Add(forumRightsPerRole);
            try
            {
                // first remove the existing rows for the role
                forumRightsPerRole.DeleteMulti((ForumRoleForumActionRightFields.RoleID == roleID).And(ForumRoleForumActionRightFields.ForumID == forumID));

                // THEN add new ones
                foreach (int actionRightID in actionRightIDs)
                {
                    ForumRoleForumActionRightEntity newForumRightPerRole = new ForumRoleForumActionRightEntity();
                    newForumRightPerRole.ActionRightID = actionRightID;
                    newForumRightPerRole.ForumID       = forumID;
                    newForumRightPerRole.RoleID        = roleID;
                    forumRightsPerRole.Add(newForumRightPerRole);
                }

                // save the new entities
                forumRightsPerRole.SaveMulti();

                // all done, commit transaction
                trans.Commit();
                return(true);
            }
            catch
            {
                // failed, rollback transaction
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Exemple #3
0
        /// <summary>
        /// Deletes the given forum from the system, including <b>all</b> threads in this forum and messages in those threads.
        /// </summary>
        /// <param name="forumID">Forum ID.</param>
        /// <returns>True if succeeded, false otherwise</returns>
        public static bool DeleteForum(int forumID)
        {
            // first all threads in this forum have to be removed, then this forum should be removed. Do this in one transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteForum");

            try
            {
                PredicateExpression forumFilter = new PredicateExpression();
                forumFilter.Add((ForumFields.ForumID == forumID));

                // remove all threads in this forum
                ThreadManager.DeleteAllThreadsInForum(forumID, trans);

                // remove all ForumRoleForumActionRight entities for this forum
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.ForumID == forumID);

                // remove the forum entity. do this by executing a direct delete statement on the database
                ForumCollection forums = new ForumCollection();
                trans.Add(forums);
                forums.DeleteMulti(forumFilter);
                trans.Commit();
                return(true);
            }
            catch
            {
                // exception occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Exemple #4
0
        /// <summary>
        /// Deletes the given forum from the system, including <b>all</b> threads in this forum and messages in those threads.
        /// </summary>
        /// <param name="forumID">Forum ID.</param>
        /// <returns>True if succeeded, false otherwise</returns>
        public static bool DeleteForum(int forumID)
        {
            // first all threads in this forum have to be removed, then this forum should be removed. Do this in one transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteForum");
            try
            {
                PredicateExpression forumFilter = new PredicateExpression();
                forumFilter.Add((ForumFields.ForumID == forumID));

                // remove all threads in this forum
                ThreadManager.DeleteAllThreadsInForum(forumID, trans);

                // remove all ForumRoleForumActionRight entities for this forum
                ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection();
                trans.Add(forumRoleActionRights);
                forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.ForumID == forumID);

                // remove the forum entity. do this by executing a direct delete statement on the database
                ForumCollection forums = new ForumCollection();
                trans.Add(forums);
                forums.DeleteMulti(forumFilter);
                trans.Commit();
                return true;
            }
            catch
            {
                // exception occured, rollback
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Exemple #5
0
        /// <summary>
        /// Saves the given set of actionrights as the set of forum action rights for the given forum / role combination.
        /// It first removes all current action rights for that combination.
        /// </summary>
        /// <param name="actionRightIDs">List of actionrights to set of this role</param>
        /// <param name="roleID">Role to use</param>
        /// <param name="forumID">Forum to use</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool SaveForumActionRightsForForumRole(List<int> actionRightIDs, int roleID, int forumID)
        {
            ForumRoleForumActionRightCollection forumRightsPerRole = new ForumRoleForumActionRightCollection();
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "SaveForumActionRights");

            // add this collection to the transaction so all actions executed through this collection will be inside the transaction
            trans.Add(forumRightsPerRole);
            try
            {
                // first remove the existing rows for the role
                forumRightsPerRole.DeleteMulti((ForumRoleForumActionRightFields.RoleID == roleID).And(ForumRoleForumActionRightFields.ForumID == forumID));

                // THEN add new ones
                foreach(int actionRightID in actionRightIDs)
                {
                    ForumRoleForumActionRightEntity newForumRightPerRole = new ForumRoleForumActionRightEntity();
                    newForumRightPerRole.ActionRightID = actionRightID;
                    newForumRightPerRole.ForumID = forumID;
                    newForumRightPerRole.RoleID = roleID;
                    forumRightsPerRole.Add(newForumRightPerRole);
                }

                // save the new entities
                forumRightsPerRole.SaveMulti();

                // all done, commit transaction
                trans.Commit();
                return true;
            }
            catch
            {
                // failed, rollback transaction
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Exemple #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();
            }
        }