Esempio n. 1
0
        public virtual IEnumerable <Post> Get(Guid userId, bool selfPosts, int pageIndex = 1, int pageSize = 1, Ordering <Post> ordering = null)
        {
            var user = Context.Set <User>().Where(x => x.Id == userId).FirstOrDefault();

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

            var entities = _entities.AsQueryable();

            if (selfPosts)
            {
                entities = entities.Where(p => p.UserId == userId);
            }
            else
            {
                var userInterests = Context.Set <UserInterest>().Where(u => u.UserId == userId);
                entities = entities.Where(p => 0 != p.PostInterests.Count(x => 0 != userInterests.Count(u => u.InterestId == x.InterestId)));
            }


            if (ordering != null)
            {
                entities = ordering.Apply(entities);
            }

            return(entities
                   .Skip((pageIndex - 1) * pageSize)
                   .Take(pageSize));
        }
Esempio n. 2
0
        virtual public IEnumerable <TEntity> Get(int pageIndex, int pageSize, Ordering <TEntity> ordering = null)
        {
            var entities = _entities.AsQueryable();

            if (ordering != null)
            {
                entities = ordering.Apply(entities);
            }

            return(entities
                   .Skip((pageIndex - 1) * pageSize)
                   .Take(pageSize).ToList());
        }
Esempio n. 3
0
        // Repository interface implementation
        public virtual IDataPortion <TEntity> GetMany(int page, int pageSize = 10, Ordering <TEntity> order = null)
        {
            // IQueriable<TEntity> goes here
            var query = (order == null)
                ? order.Apply(DataContext.Set <TEntity>())
                : DataContext.Set <TEntity>();

            var totalItemsInTable = query.Count();

            if (page * pageSize > totalItemsInTable)
            {
                throw new ArgumentOutOfRangeException("Attempt to access elements outside of " + typeof(TEntity) + " table bounds in the database");
            }

            var resultationEntities = (page == 1) ? query.Take(pageSize) : query.Skip((page - 1) * pageSize).Take(pageSize);

            return(new DataPortion <TEntity>(/*new List<TEntity>()*/ resultationEntities, totalItemsInTable));
        }
Esempio n. 4
0
        private void ExpandCompositeOrderings(OrderByClause orderByClause)
        {
            var orderings = orderByClause.Orderings;
            var copy      = new Ordering[orderings.Count];

            orderings.CopyTo(copy, 0);

            copy.Apply(o => orderings.Remove(o));

            foreach (var o in copy)
            {
                if (o.Expression is LuceneCompositeOrderingExpression)
                {
                    var ex = (LuceneCompositeOrderingExpression)o.Expression;

                    ex.Fields.Apply(f => orderings.Add(new Ordering(f, o.OrderingDirection)));
                }
                else
                {
                    orderings.Add(o);
                }
            }
        }