Example #1
0
        /// <summary>
        /// Method to select an AclAction.
        /// </summary>
        /// <param name="op">ACL Actions entities select options to perform query.</param>
        /// <param name="nullable"></param>
        /// <returns>A ACL Action entity or null if not found.</returns>
        public AclActionEntity Select(AclActionOptionsSelect op, bool nullable = false)
        {
            // Initialize query.
            IQueryable <AclActionEntity> query = (Connector as DatabaseContextCore).AclActions;

            // Load ACL Groups dependencies if required.
            if (op.IsDependOn(EnumEntitiesDependencies.AclGroupsInAclActions))
            {
                query = query.Include(x => x.AclGroupsInAclActions);
            }

            if (op.PrimaryKey > 0)
            {
                if (nullable)
                {
                    return(query.SingleOrNull(x => x.AclActionId == op.PrimaryKey));
                }

                return(query.SingleOrDefault(x => x.AclActionId == op.PrimaryKey));
            }

            if (op.Action != "")
            {
                if (nullable)
                {
                    return(query.SingleOrNull(x => x.Action == op.Action));
                }

                return(query.SingleOrDefault(x => x.Action == op.Action));
            }

            throw new ArgumentNullException(nameof(op), "AclActionOptionsSelect must contains no empty or null value Primary Key or Action for selection.");
        }
Example #2
0
        public AclActionEntity RemoveAclGroupDependency(int aclActionId, int aclGroupId, bool save = true)
        {
            AclActionOptionsSelect options = new AclActionOptionsSelect {
                PrimaryKey = aclActionId
            };

            options.Dependencies.Add(EnumEntitiesDependencies.AclGroupsInAclActions);

            AclActionEntity item = Select(options);

            item.AclGroupsInAclActions.Remove(item.AclGroupsInAclActions.SingleOrDefault(x => x.AclGroupId == aclGroupId));

            return(Update(item, save));
        }
Example #3
0
        public AclActionEntity AddAclGroupDependency(int aclActionId, int aclGroupId, bool save = true)
        {
            AclActionOptionsSelect options = new AclActionOptionsSelect {
                PrimaryKey = aclActionId
            };

            options.Dependencies.Add(EnumEntitiesDependencies.AclGroupsInAclActions);

            AclActionEntity item = Select(options);

            item.AclGroupsInAclActions.Add(new AclGroupsInAclActions {
                AclGroupId = aclGroupId
            });

            return(Update(item, save));
        }
Example #4
0
        public async Task <AclActionEntity> RemoveAclGroupDependenciesAsync(int aclActionId, int aclGroupId, bool save = true)
        {
            int result = await(Connector as DatabaseContextCore).Database.ExecuteSqlCommandAsync(
                $"DELETE FROM AclGroupsInAclActions WHERE AclActionId = {aclActionId} AND AclGroupId = {aclGroupId}"
                );

            if (save)
            {
                Save();
            }

            AclActionOptionsSelect options = new AclActionOptionsSelect {
                PrimaryKey = aclActionId
            };

            options.Dependencies.Add(EnumEntitiesDependencies.AclGroupsInAclActions);

            return(Select(options));
        }