Exemplo n.º 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
                }));
            }
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            var model = new ContentTypeUsageViewModels();

            try
            {
                var epiId = System.Web.HttpContext.Current.Request.QueryString["id"];

                var contentLoader            = ServiceLocator.Current.GetInstance <IContentLoader>();
                var contentVersionRepository = ServiceLocator.Current.GetInstance <IContentVersionRepository>();

                var contentTypes = ContentTypeUsageHelper.ListAllContentTypes().ToList();

                var content = contentLoader.Get <IContent>(new ContentReference(epiId));
                model.ContentTypeId = content.ContentTypeID;
                model.ContentType   = contentTypes?.FirstOrDefault(t => t.ID == content.ContentTypeID)?.LocalizedFullName;

                model.AllContentTypes = ContentTypeUsageHelper
                                        .ListAllReferenceOfContentInstance(content.ContentLink.ID, 1, 1000, "", out _)
                                        .Select(p =>
                {
                    var contentVersion = contentVersionRepository.List(p.ContentLink)
                                         ?.OrderByDescending(x => x.Saved)
                                         ?.FirstOrDefault(version => version.IsMasterLanguageBranch);

                    var a = contentVersionRepository.List(p.ContentLink)
                            ?.OrderByDescending(x => x.Saved);

                    return(new ContentItem
                    {
                        ContentId = p.ContentLink.ID,
                        ContentName = p.Name,
                        ContentUrl = ContentTypeUsageHelper.ResolveEditUrl(p),
                        ContentTypeId = p.ContentTypeID,
                        ContentType = contentTypes?.FirstOrDefault(t => t.ID == p.ContentTypeID)?.LocalizedFullName,
                        PublicationDate = contentVersion?.Saved,
                        ChangedBy = contentVersion?.SavedBy,
                        Language = contentVersion?.LanguageBranch
                    });
                });


                return(View(GetViewLocation("Index"), model));
            }
            catch (Exception ex)
            {
                Logger.Error("Cannot retrieve list of content types", ex);
                return(View(GetViewLocation("Index"), model));
            }
        }
Exemplo n.º 4
0
        public ActionResult ContentTypeList(int id)
        {
            var model = new ContentTypeUsageViewModels();

            try
            {
                var contentVersionRepository = ServiceLocator.Current.GetInstance <IContentVersionRepository>();

                var contentTypes = ContentTypeUsageHelper.ListAllContentTypes();

                model.AllContentTypes = ContentTypeUsageHelper
                                        .ListAllContentOfType(id, 1, 1000, "", out _)
                                        .Select(p =>
                {
                    var contentVersion = contentVersionRepository.List(p.ContentLink)
                                         ?.OrderByDescending(x => x.Saved)
                                         ?.FirstOrDefault(version => version.IsMasterLanguageBranch);

                    var a = contentVersionRepository.List(p.ContentLink)
                            ?.OrderByDescending(x => x.Saved);

                    return(new ContentItem
                    {
                        ContentId = p.ContentLink.ID,
                        ContentName = p.Name,
                        ContentUrl = ContentTypeUsageHelper.ResolveEditUrl(p),
                        ContentType = contentTypes?.FirstOrDefault(t => t.ID == p.ContentTypeID)?.LocalizedFullName,
                        PublicationDate = contentVersion?.Saved,
                        ChangedBy = contentVersion?.SavedBy,
                        Language = contentVersion?.LanguageBranch
                    });
                });


                return(View(GetViewLocation("ContentTypeList"), model));
            }
            catch (Exception ex)
            {
                Logger.Error("Cannot retrieve list of content types", ex);
                return(View(GetViewLocation("ContentTypeList"), model));
            }
        }