Exemple #1
0
        /// <summary>Creates a new, empty RoleSystemActionRightEntity object.</summary>
        /// <returns>A new, empty RoleSystemActionRightEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new RoleSystemActionRightEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewRoleSystemActionRight
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
Exemple #2
0
        /// <summary>
        /// Modifies the given role: it resets the system action rights for the given role to the given set of action rights and it modifies
        /// the role description for the given role. If the user specified a role description that is already available, false will be returned to signal
        /// that the save failed.
        /// </summary>
        /// <param name="actionRightIDs">The action rights.</param>
        /// <param name="roleID">The role ID.</param>
        /// <param name="roleDescription">The role description.</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool ModifyRole(List<int> actionRightIDs, int roleID, string roleDescription)
        {
            // read the existing role entity from the database.
            RoleEntity roleToModify = new RoleEntity(roleID);
            if(roleToModify.IsNew)
            {
                // not found
                return false;
            }

            // check if the description is different. If so, we've to check if the new roledescription is already present. If so, we'll
            // abort the save
            if(roleToModify.RoleDescription != roleDescription)
            {
                if(CheckIfRoleDescriptionIsPresent(roleDescription))
                {
                    // new description, is already present, fail
                    return false;
                }
            }

            // all set. We're going to delete all Role - SystemAction Rights combinations first, as we're going to re-insert them later on.
            // We'll use a transaction to be able to roll back all our changes if something fails.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "ModifyRole");
            try
            {
                RoleSystemActionRightCollection roleActionRights = new RoleSystemActionRightCollection();
                // add this collection to the transaction so all actions executed through this collection will be inside the transaction
                trans.Add(roleActionRights);
                // delete all role-systemactionright combinations directly from the database, by issuing a direct delete on the database, using a filter
                // on roleid
                roleActionRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID);

                // add new role-systemactionright entities which we'll save to the database after that
                foreach(int actionRightID in actionRightIDs)
                {
                    RoleSystemActionRightEntity toAdd = new RoleSystemActionRightEntity();
                    toAdd.ActionRightID = actionRightID;
                    toAdd.RoleID = roleID;
                    roleActionRights.Add(toAdd);
                }
                // save the new entities to the database
                roleActionRights.SaveMulti();

                // we'll now save the role and the role description, if it's changed. Otherwise the save action will be a no-op.
                // add it to the transaction
                trans.Add(roleToModify);
                roleToModify.RoleDescription = roleDescription;
                roleToModify.Save();

                // all done, commit the transaction
                trans.Commit();
                return true;
            }
            catch
            {
                // failed, roll back transaction.
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }