Esempio n. 1
0
        /// <summary>
        /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser
        /// method or a simple lambda expression
        /// </summary>
        /// <param name="filter">the Expression to use to filter objects from the data store</param>
        /// <returns>RepositoryResultList</returns>
        public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter)
        {
            RepositoryResultList <T> result = new RepositoryResultList <T>();

            try
            {
                result.Entities = _ctx.Set <T>().Where(filter.Compile());
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                // LogError(ex);
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets All items of Type T from the data store
        /// </summary>
        /// <returns>IEnumerable of the specified Type/></returns>
        public RepositoryResultList <T> GetAll()
        {
            RepositoryResultList <T> result = new RepositoryResultList <T>();

            try
            {
                result.Entities = _ctx.Set <T>().AsEnumerable();
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                // LogError(ex);
                _logger.LogError($"Error in Repository {ex}");
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all of T from the data store
        /// </summary>
        /// <param name="includes">A list of property names to return in the object graph</param>
        /// <returns>RepositoryReslutList</returns>
        public RepositoryResultList <T> GetAll(params string[] includes)
        {
            RepositoryResultList <T> result = new RepositoryResultList <T>();

            try
            {
                var query = _ctx.Set <T>().Where(t => true);
                foreach (string include in includes)
                {
                    query = (IQueryable <T>)query.Include(include);
                }
                result.Entities = query.ToList();
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                //   LogError(ex);
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Performs a find on the repository given the specified Type and Filter expression (this will come from the FilterStore.FilterForUser
        /// method or a simple lambda expression
        /// </summary>
        /// <param name="filter">the Expression to use to filter objects from the data store</param>
        /// <param name="includes">a params string array of property names that will be included in the resulting object graph for each item</param>
        /// <returns>RepositoryResultList</returns>
        public RepositoryResultList <T> Find(System.Linq.Expressions.Expression <Func <T, bool> > filter, params string[] includes)
        {
            RepositoryResultList <T> result = new RepositoryResultList <T>();

            try
            {
                var query = _ctx.Set <T>().Where(t => true);
                foreach (string include in includes)
                {
                    query = query.Include(include);
                }
                result.Entities = query.Where(filter.Compile());
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                // LogError(ex);
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }