Esempio n. 1
0
        public object Post(string id, ListQueryModel model)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            var part = GetProjectionPartRecord(model.ViewId);

            if (part == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            var pluralService = PluralizationService.CreateService(new CultureInfo("en-US"));

            id = pluralService.Singularize(id);
            string filterDescription = null;

            return(GetFilteredRecords(id, part, out filterDescription, model, p => {
                _gridService.GenerateSortCriteria(id, model.Sidx, model.Sord, p.Record.QueryPartRecord.Id);
                var totalRecords = _projectionManager.GetCount(p.Record.QueryPartRecord.Id);
                var pageSize = model.Rows;
                var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
                var pager = new Pager(Services.WorkContext.CurrentSite, model.Page, pageSize);
                var records = GetLayoutComponents(p, pager.GetStartIndex(), pager.PageSize);

                return new {
                    totalPages = totalPages,
                    page = model.Page,
                    totalRecords = totalRecords,
                    rows = records,
                    filterDescription = filterDescription
                };
            }));
        }
Esempio n. 2
0
        public ActionResult QueryResults(int queryId, int skip = 0, int count = 12)
        {
            if (!_services.Authorizer.Authorize(Orchard.Projections.Permissions.ManageQueries, T("Not allowed to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var query = _contentManager.Get(queryId).As <QueryPart>();

            if (query == null)
            {
                return(HttpNotFound(T("Query not found.").Text));
            }
            var contentItems  = _projectionManager.GetContentItems(queryId, skip, count);
            var totalCount    = _projectionManager.GetCount(queryId);
            var contentShapes = contentItems.Select(item =>
                                                    _contentManager.BuildDisplay(item, "SummaryAdmin"));

            var list = Shape.List();

            list.AddRange(contentShapes);
            list.Attributes.Add("data-total-count", totalCount.ToString(CultureInfo.InvariantCulture));

            return(new ShapePartialResult(this, list));
        }