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

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewForumRoleForumActionRight
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
예제 #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 async Task <bool> SaveForumActionRightsForForumRoleAsync(List <int> actionRightIDs, int roleId, int forumId)
        {
            var forumRightsPerRole = new EntityCollection <ForumRoleForumActionRightEntity>();

            foreach (var actionRightId in actionRightIDs)
            {
                var newForumRightPerRole = new ForumRoleForumActionRightEntity
                {
                    ActionRightID = actionRightId,
                    ForumID       = forumId,
                    RoleID        = roleId
                };
                forumRightsPerRole.Add(newForumRightPerRole);
            }

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

                try
                {
                    // first remove the existing rows for the role. Do this by a query directly on the database.
                    await adapter.DeleteEntitiesDirectlyAsync(typeof(ForumRoleForumActionRightEntity),
                                                              new RelationPredicateBucket((ForumRoleForumActionRightFields.RoleID.Equal(roleId))
                                                                                          .And(ForumRoleForumActionRightFields.ForumID.Equal(forumId))))
                    .ConfigureAwait(false);

                    // then save the new entities
                    await adapter.SaveEntityCollectionAsync(forumRightsPerRole).ConfigureAwait(false);

                    // all done, commit transaction
                    adapter.Commit();
                    return(true);
                }
                catch
                {
                    // failed, rollback transaction
                    adapter.Rollback();
                    throw;
                }
            }
        }
예제 #3
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();
            }
        }