Exemplo n.º 1
0
        protected BioRepositoryQuery <T> ConfigureQuery <T>(BioRepositoryQuery <T> query, int page = 0)
            where T : class, IEntity, ISiteEntity
        {
            if (ControllerContext.HttpContext.Request.Query.ContainsKey("order"))
            {
                query = query.OrderByString(ControllerContext.HttpContext.Request.Query["order"]);
            }
            else
            {
                query = query.OrderByDescending(e => e.DateUpdated);
            }

            var offset = 0;

            if (page > 0)
            {
                Page   = page;
                offset = (Page - 1) * ItemsPerPage;
            }
            else if (ControllerContext.HttpContext.Request.Query.ContainsKey("page"))
            {
                Page = int.Parse(ControllerContext.HttpContext.Request.Query["page"]);
                if (Page < 1)
                {
                    Page = 1;
                }
                offset = (Page - 1) * ItemsPerPage;
            }

            return(query.ForSite(Site).Skip(offset).Take(ItemsPerPage));
        }
Exemplo n.º 2
0
        protected BioRepositoryQuery <TEntity> ConfigureQuery(BioRepositoryQuery <TEntity> query, int limit, int offset, string order,
                                                              string filter)
        {
            if (!string.IsNullOrEmpty(filter) &&
                filter != "null")
            {
                var mod4 = filter.Length % 4;
                if (mod4 > 0)
                {
                    filter += new string('=', 4 - mod4);
                }

                var data          = Convert.FromBase64String(filter);
                var decodedString = HttpUtility.UrlDecode(Encoding.UTF8.GetString(data));
                if (!string.IsNullOrEmpty(decodedString))
                {
                    query = query.WhereByString(decodedString);
                }
            }

            if (!string.IsNullOrEmpty(order))
            {
                query = query.OrderByString(order);
            }

            if (limit > 0)
            {
                query = query.Take(limit);
            }

            if (offset > 0)
            {
                query = query.Skip(offset);
            }

            return(query);
        }