public ActionResult Items(string name, string slug, ContentQuery query, string parentID = "", string format = "json")
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            //if (string.IsNullOrEmpty(slug))
            //  throw new ArgumentNullException("slug");

            var list = App.Get().CurrentWeb.Lists[name];
            //ViewBag.List = list;
            ContentViewDecorator view;

            if (string.IsNullOrEmpty(slug))
            {
                view = list.Views.FirstOrDefault();
            }
            else
            {
                view = list.Views[slug];
            }

            if (!string.IsNullOrEmpty(query.Filter))
            {
                query.Filter = query.GetFilterExpression();
            }

            if (!string.IsNullOrEmpty(parentID))
            {
                if (string.IsNullOrEmpty(query.Filter))
                {
                    query.Filter = "parentId='" + parentID + "'";
                }
                else
                {
                    query.Filter = " AND parentId='" + parentID + "'";
                }
            }

            if (view == null)
            {
                throw new ContentViewNotFoundException();
            }

            if (!view.IsAuthorized(HttpContext))
            {
                return(new HttpUnauthorizedResult());
            }

            var results = view.Items(query);

            if (format == "xml")
            {
                return(Content(results.Element().OuterXml(), "text/xml", Encoding.UTF8));
            }

            var model     = results.Items.Select(i => list.GetItem(i.ID).ToObject()).ToList();
            var jsonModel = new
            {
                Model = model,
                Total = query.Total
            };

            var jstr = JsonConvert.SerializeObject(jsonModel, new JsonSerializerSettings()
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            });

            return(Content(jstr, "application/json", Encoding.UTF8));
        }
        public ActionResult Items(string name, string slug, ContentQuery query, string parentID = "", string format = "json")
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            //if (string.IsNullOrEmpty(slug))
            //  throw new ArgumentNullException("slug");

            var list = App.Get().CurrentWeb.Lists[name];
            //ViewBag.List = list;
            ContentViewDecorator view;

            if (string.IsNullOrEmpty(slug))
                view = list.Views.FirstOrDefault();
            else
                view = list.Views[slug];

            if (!string.IsNullOrEmpty(query.Filter))
                query.Filter = query.GetFilterExpression();

            if (!string.IsNullOrEmpty(parentID))
            {
                if (string.IsNullOrEmpty(query.Filter))
                    query.Filter = "parentId='" + parentID + "'";
                else
                {
                    query.Filter = " AND parentId='" + parentID + "'";
                }
            }

            if (view == null)
                throw new ContentViewNotFoundException();

            if (!view.IsAuthorized(HttpContext))
                return new HttpUnauthorizedResult();

            var results = view.Items(query);

            if (format == "xml")
                return Content(results.Element().OuterXml(), "text/xml", Encoding.UTF8);

            var model = results.Items.Select(i => list.GetItem(i.ID).ToObject()).ToList();
            var jsonModel = new
            {
                Model = model,
                Total = query.Total
            };

            var jstr = JsonConvert.SerializeObject(jsonModel, new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat });
            return Content(jstr, "application/json", Encoding.UTF8);
        }