public IEnumerable <Product> GetPaginatedEntities(QueryOptions queryOptions)
        {
            using (CoreContext entityContext = new CoreContext())
            {
                var query = from a in entityContext.ProductSet
                            select a;

                query = (queryOptions.FilterFieldType == "string")
                    ? query.Where(p => p.Code.Contains(queryOptions.FilterOption) ||
                                  p.Name.Contains(queryOptions.FilterOption) ||
                                  p.AssetGL.Contains(queryOptions.FilterOption) ||
                                  p.LiabilityGL.Contains(queryOptions.FilterOption) ||
                                  p.IncomeGL.Contains(queryOptions.FilterOption) ||
                                  p.ExpenseGL.Contains(queryOptions.FilterOption)
                                  )
                    : query.Where(queryOptions.FilterField + " = " + queryOptions.FilterOption);

                var queryArray = query.OrderBy(queryOptions.Sort)
                                 .Skip(
                    QueryOptionsCalculator.CalculateStart(queryOptions)
                    ).Take(queryOptions.PageSize)
                                 .ToList();

                return(queryArray);
            }
        }
        public List <Author> Get(QueryOptions queryOptions)
        {
            var start   = QueryOptionsCalculator.CalculateStart(queryOptions);
            var authors = db.Authors
                          .OrderBy(queryOptions.Sort)
                          .Skip(start)
                          .Take(queryOptions.PageSize);

            queryOptions.TotalPages = (int)Math.Ceiling((double)db.Authors.Count() / queryOptions.PageSize);

            return(authors.ToList());
        }
Example #3
0
        public List <Author> Get(QueryOptions queryOptions)
        {
            var start = QueryOptionsCalculator.CalculateStart(queryOptions);

            var authors = db.Authors.
                          OrderBy(queryOptions.Sort).
                          Skip(start).
                          Take(queryOptions.PageSize);

            queryOptions.TotalPages = QueryOptionsCalculator.CaclulateTotalPages(
                db.Authors.Count(), queryOptions.PageSize);

            return(authors.ToList());
        }
        public List <Author> Get(QueryOptions queryOptions)
        {
            //1 获得起始页码
            var start = QueryOptionsCalculator.CalculateStart(queryOptions);
            //2 获得作者集合
            var authors = db.Authors.
                          OrderBy(queryOptions.Sort).
                          Skip(start).
                          Take(queryOptions.PageSize);

            //3 获得总页码
            queryOptions.TotalPages = QueryOptionsCalculator.CalculateTotalPages(db.Authors.Count(), queryOptions.PageSize);

            return(authors.ToList());
        }
Example #5
0
        public List <Book> Get(QueryOptions queryOptions)
        {
            // First time will be Id
            if (queryOptions.SortField == "Id")
            {
                queryOptions.SortField = "Title";
            }

            var start = QueryOptionsCalculator.CalculateStart(queryOptions);

            var books = db.Book.
                        OrderBy(queryOptions.Sort).
                        Skip(start).
                        Take(queryOptions.PageSize);

            queryOptions.TotalPages =
                QueryOptionsCalculator.CalculateTotalPages(db.Book.Count(), queryOptions.PageSize);

            return(books.ToList());
        }
Example #6
0
        public List <Author> Get(QueryOptions queryOptions, int bookId = 0)
        {
            // First time will be Id
            if (queryOptions.SortField == "Id")
            {
                queryOptions.SortField = "LastName";
            }

            var start = QueryOptionsCalculator.CalculateStart(queryOptions);

            if (bookId == 0)
            {
                var authors = db.Author.
                              OrderBy(queryOptions.Sort).
                              Skip(start).
                              Take(queryOptions.PageSize);

                queryOptions.TotalPages =
                    QueryOptionsCalculator.CalculateTotalPages(db.Author.Count(), queryOptions.PageSize);

                return(authors.ToList());
            }
            else
            {
                var authors = (from a in db.Author
                               join b in db.BookAuthor
                               on a.Id equals
                               b.AuthorId
                               where b.BookId == bookId
                               select a).
                              OrderBy(queryOptions.Sort);

                queryOptions.TotalPages = 1;

                return(authors.ToList());
            }
        }