示例#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
                };
            }));
        }