Esempio n. 1
0
        /// <summary>
        /// The get entities.
        /// </summary>
        /// <param name="collection">
        /// The collection.
        /// </param>
        /// <typeparam name="T">
        /// The type of <see cref="IEntity"/>
        /// </typeparam>
        /// <returns>
        /// The <see cref="IEnumerable{T}"/>.
        /// </returns>
        public static IEnumerable <T> GetEntities <T>(this IEntityCollection collection)
            where T : class, IEntity
        {
            var resolved = collection.ResolveProvider();

            return(resolved == null?Enumerable.Empty <T>() : resolved.GetEntities <T>());
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a generic page of Entities.
        /// </summary>
        /// <param name="collection">
        /// The collection.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page"/>.
        /// </returns>
        public static Page <object> GetPagedEntities(
            this IEntityCollection collection,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending)
        {
            var resolved = collection.ResolveProvider();

            return(resolved == null
                       ? new Page <object>()
                       : resolved.GetPagedEntities(page, itemsPerPage, sortBy, sortDirection));
        }
Esempio n. 3
0
        /// <summary>
        /// The resolve provider.
        /// </summary>
        /// <param name="collection">
        /// The collection.
        /// </param>
        /// <typeparam name="T">
        /// The type of provider
        /// </typeparam>
        /// <returns>
        /// The <see cref="EntityCollectionProviderBase"/>.
        /// </returns>
        internal static T ResolveProvider <T>(this IEntityCollection collection)
            where T : class
        {
            var provider = collection.ResolveProvider();

            if (provider == null)
            {
                return(null);
            }

            if (provider is T)
            {
                return(provider as T);
            }

            LogHelper.Debug(typeof(EntityCollectionExtensions), "Provider was resolved but was not of expected type.");

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// The get entities.
        /// </summary>
        /// <param name="collection">
        /// The collection.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Object}"/>.
        /// </returns>
        public static IEnumerable <object> GetEntities(this IEntityCollection collection)
        {
            var resolved = collection.ResolveProvider();

            return(resolved == null?Enumerable.Empty <object>() : resolved.GetEntities());
        }
Esempio n. 5
0
        /// <summary>
        /// The resolve validated provider.
        /// </summary>
        /// <param name="collection">
        /// The collection.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <typeparam name="T">
        /// The type of the <see cref="IEntity"/>
        /// </typeparam>
        /// <returns>
        /// The <see cref="EntityCollectionProviderBase"/>.
        /// </returns>
        internal static EntityCollectionProviderBase <T> ResolveValidatedProvider <T>(this IEntityCollection collection, T entity) where T : class, IEntity
        {
            var resolved = collection.ResolveProvider();

            return(resolved is EntityCollectionProviderBase <T>?resolved as EntityCollectionProviderBase <T> : null);
        }