Beispiel #1
0
        /// <summary>
        /// Finds a rule with the given primary key value.
        /// </summary>
        /// <param name="id">The primary key for the item to be found.</param>
        /// <param name="fields">The related fields to include in the query results.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <RuleItem> FindByIdAsync(int id, RuleField fields, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var ruleEntity = await Rules.FindAsync(cancellationToken, id);

            if (ruleEntity == null)
            {
                return(null);
            }
            return(LoggingQueries.ToRuleItem(ruleEntity));
        }
Beispiel #2
0
        /// <summary>
        /// Finds a collection of rules with the given values.
        /// </summary>
        /// <param name="userId">The user identifier for the item to be found.</param>
        /// <param name="fields">The related fields to include in the query results.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ListResult <RuleItem> > FindAllAsync(int userId, RuleField fields, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var rules = await Rules.Where(userId).ToArrayAsync(cancellationToken);

            var list = new List <RuleItem>();

            foreach (var rule in rules)
            {
                list.Add(LoggingQueries.ToRuleItem(rule));
            }
            return(ListResult.Create(list));
        }