Esempio n. 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 async Task <bool> DeleteRoleAsync(int roleId)
        {
            var toDelete = await SecurityGuiHelper.GetRoleAsync(roleId);

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

            using (var adapter = new DataAccessAdapter())
            {
                await adapter.StartTransactionAsync(IsolationLevel.ReadCommitted, "DeleteRole").ConfigureAwait(false);

                try
                {
                    // remove the role - forum - action right entities
                    await adapter.DeleteEntitiesDirectlyAsync(typeof(ForumRoleForumActionRightEntity),
                                                              new RelationPredicateBucket(ForumRoleForumActionRightFields.RoleID.Equal(roleId))).ConfigureAwait(false);

                    // Remove role-audit action entities
                    await adapter.DeleteEntitiesDirectlyAsync(typeof(RoleAuditActionEntity),
                                                              new RelationPredicateBucket(RoleAuditActionFields.RoleID.Equal(roleId))).ConfigureAwait(false);

                    ;

                    // remove Role - systemright entities
                    await adapter.DeleteEntitiesDirectlyAsync(typeof(RoleSystemActionRightEntity),
                                                              new RelationPredicateBucket(RoleSystemActionRightFields.RoleID.Equal(roleId))).ConfigureAwait(false);

                    ;

                    // remove Role - user entities
                    await adapter.DeleteEntitiesDirectlyAsync(typeof(RoleUserEntity),
                                                              new RelationPredicateBucket(RoleUserFields.RoleID.Equal(roleId))).ConfigureAwait(false);

                    ;

                    // delete the actual role
                    await adapter.DeleteEntityAsync(toDelete).ConfigureAwait(false);

                    ;
                    adapter.Commit();
                    return(true);
                }
                catch
                {
                    // error occured, rollback
                    adapter.Rollback();
                    throw;
                }
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Modifies the given IPBan
        /// </summary>
        /// <param name="toUpdate">the dto containing the values to update the associated entity with</param>
        /// <returns>True if succeeded, false otherwise</returns>
        public static async Task <bool> ModifyIPBanAsync(IPBanDto toUpdate)
        {
            if (toUpdate == null)
            {
                return(false);
            }

            var ipBan = await SecurityGuiHelper.GetIPBanAsync(toUpdate.IPBanID);

            if (ipBan == null)
            {
                return(false);
            }

            ipBan.UpdateFromIPBan(toUpdate);
            using (var adapter = new DataAccessAdapter())
            {
                return(await adapter.SaveEntityAsync(ipBan).ConfigureAwait(false));
            }
        }