Exemple #1
0
        public virtual IMemberPermission AddMemberPermission <TSource, TargetType>(SecurityOperation operation, OperationState state, string memberName, Expression <Func <TSource, TargetType, bool> > criteria) where TSource : BaseSecurityDbContext
        {
            if (operation.HasFlag(SecurityOperation.Create))
            {
                throw new ArgumentException("The create value of the 'operations' parameter is incorrect in this context. Only the Read and Write operations can be granted by a member permission.");
            }

            if (operation.HasFlag(SecurityOperation.Delete))
            {
                throw new ArgumentException("The delete value of the 'operations' parameter is incorrect in this context. Only the Read and Write operations can be granted by a member permission.");
            }

            Type         targetType   = typeof(TargetType);
            PropertyInfo targetMember = targetType.GetProperty(memberName);

            if (targetMember == null)
            {
                throw new ArgumentException(string.Format("{0} type doesn't contain {1} property.", targetType.Name, memberName));
            }

            var memberPermission = new MemberPermission <TSource, TargetType>(operation, state, memberName, criteria);

            memberPermission.Type           = typeof(TargetType);
            memberPermission.Operations     = operation;
            memberPermission.OperationState = state;
            permissions.Add(memberPermission);
            return(memberPermission);
        }
        public virtual IMemberPermission AddMemberPermission <TSource, TargetType>(SecurityOperation operation, OperationState state, string memberName, Expression <Func <TSource, TargetType, bool> > criteria) where TSource : BaseSecurityDbContext
        {
            if (operation.HasFlag(SecurityOperation.Create))
            {
                throw new ArgumentException("The create value of the 'operations' parameter is incorrect in this context. Only the Read and Write operations can be granted by a member permission.");
            }
            if (operation.HasFlag(SecurityOperation.Delete))
            {
                throw new ArgumentException("The delete value of the 'operations' parameter is incorrect in this context. Only the Read and Write operations can be granted by a member permission.");
            }
            SecurityMemberPermission memberPermission = new SecurityMemberPermission();

            memberPermission.Type           = typeof(TargetType);
            memberPermission.Criteria       = criteria;
            memberPermission.Operations     = operation;
            memberPermission.OperationState = state;
            memberPermission.MemberName     = memberName;
            this.MemberPermissions.Add(memberPermission);
            return(memberPermission);
        }