Пример #1
0
        public JsonResult GetInstances(int contentTypeId, int page, int pageSize = 10, string query = "")
        {
            var total = 0;

            try
            {
                var result = ContentTypeUsageHelper.ListAllContentOfType(contentTypeId, page, pageSize, query, out total);

                return(Json(new
                {
                    status = true,
                    page = page,
                    pageSize = pageSize,
                    total = total,
                    items = result.Select(t => new
                    {
                        Id = t.ContentLink.ID,
                        Name = t.Name,
                        ViewLink = ContentTypeUsageHelper.ResolveViewUrl(t),
                        EditLink = ContentTypeUsageHelper.ResolveEditUrl(t),
                        IsBlockType = typeof(BlockData).IsAssignableFrom(t.GetType().BaseType)
                    })
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Error("Cannot retrieve list of instances", ex);
                return(Json(new
                {
                    status = true,
                    message = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult GetReferences(int blockId, int page, int pageSize = 10, string query = "")
        {
            try
            {
                var result = ContentTypeUsageHelper.ListAllReferenceOfContentInstance(blockId, page, pageSize, query, out var total);

                return(Json(new
                {
                    status = true,
                    page,
                    pageSize,
                    total,
                    items = result.Select(t => new
                    {
                        Id = t.ContentLink.ID,
                        t.Name,
                        ViewLink = ContentTypeUsageHelper.ResolveViewUrl(t),
                        EditLink = ContentTypeUsageHelper.ResolveEditUrl(t),
                        IsBlockType = typeof(BlockData).IsAssignableFrom(t.GetType().BaseType)
                    })
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    status = false,
                    message = ex.Message
                }));
            }
        }