コード例 #1
0
        /// <summary>
        /// Gets the total number of attachments to approve.
        /// </summary>
        /// <param name="accessableForums">The accessable forums by the user calling.</param>
        /// <param name="forumsWithApprovalRight">The forums the calling user has attachment approval rights.</param>
        /// <param name="forumsWithThreadsFromOthers">The forums the calling user can view normal threads from others.</param>
        /// <param name="userID">The user ID of the calling user.</param>
        /// <returns>the # of attachments with the approval state which are approvable by the calling user</returns>
        public static int GetTotalNumberOfAttachmentsToApprove(List <int> accessableForums, List <int> forumsWithApprovalRight,
                                                               List <int> forumsWithThreadsFromOthers, int userID)
        {
            if ((accessableForums == null) || (accessableForums.Count <= 0))
            {
                // doesn't have access to any forum, return
                return(0);
            }
            if ((forumsWithApprovalRight == null) || (forumsWithApprovalRight.Count <= 0))
            {
                // doesn't have a forum with attachment approval right
                return(0);
            }

            // we'll use a GetDBCount call, where we'll specify a filter.

            // we've to join attachment - message - thread, so we've to create a RelationCollection with the necessary relations.
            RelationCollection relations = new RelationCollection();

            relations.Add(AttachmentEntity.Relations.MessageEntityUsingMessageID);
            relations.Add(MessageEntity.Relations.ThreadEntityUsingThreadID);

            // we've to filter the list of attachments based on the forums accessable by the calling user, the list of forums the calling user has approval rights
            // on and by the forums on which the user can see other user's threads. We'll create a predicate expression for this, and will add for each of these
            // filters a separate predicate to this predicate expression and specify AND, so they all have to be true
            PredicateExpression filter = CreateAttachmentFilter(accessableForums, forumsWithApprovalRight, forumsWithThreadsFromOthers, userID, false);

            AttachmentCollection attachments = new AttachmentCollection();

            return(attachments.GetDbCount(filter, relations));
        }