Ejemplo n.º 1
0
        /// <summary>
        /// Executes a query to get a single entity of the specified type using an integer identifier. Use this
        /// as a short cut instead of creating a dedicated IQuery class.
        /// </summary>
        /// <typeparam name="TEntity">type of entity to return</typeparam>
        /// <param name="id">Id of the entity to get. Values less than 1 will always return default(TEntity).</param>
        /// <param name="ex">
        /// If specified this will execute the query under
        /// the specified context. Useful for running the query under a higher privalidge account.
        /// </param>
        /// <returns>TEntity instance if found; otherwise default(TEntity)</returns>
        public static async Task <TEntity> GetByIdAsync <TEntity>(this IQueryExecutor executor, int id, IExecutionContext ex)
        {
            if (id <= 0)
            {
                return(default(TEntity));
            }
            var query = new GetByIdQuery <TEntity>()
            {
                Id = id
            };

            return(await executor.ExecuteAsync(query, ex));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes a query to get a single entity of the specified type using an integer identifier. Use this
        /// as a short cut instead of creating a dedicated IQuery class.
        /// </summary>
        /// <typeparam name="TEntity">type of entity to return</typeparam>
        /// <param name="id">Id of the entity to get. Values less than 1 will always return default(TEntity).</param>
        /// <param name="ex">
        /// If specified this will execute the query under
        /// the specified context. Useful for running the query under a higher privalidge account.
        /// </param>
        /// <returns>TEntity instance if found; otherwise default(TEntity)</returns>
        public static TEntity GetById <TEntity>(this IQueryExecutor executor, int id, IExecutionContext ex)
        {
            if (id <= 0)
            {
                return(default(TEntity));
            }
            var query = new GetByIdQuery <TEntity>()
            {
                Id = id
            };

            return(executor.Execute(query, ex));
        }