Example #1
0
        public async Task <ActionResult> New(string tabId, int parentId, int id)
        {
            var folder = ContentFolderService.New(parentId, id);
            var model  = ContentFolderViewModel.Create(folder, tabId, parentId);

            return(await JsonHtml("FolderProperties", model));
        }
Example #2
0
        public ActionResult RemoveFile(int parentId, string id)
        {
            string[] ids    = { id };
            var      result = ContentFolderService.RemoveFiles(parentId, ids);

            return(Json(result));
        }
Example #3
0
        /// <summary>
        /// 栏目详细页
        /// </summary>
        public ActionResult FolderDetail(int contentFolderId, int pageSize = 15, int pageIndex = 1)
        {
            var contentFolderService = new ContentFolderService();
            var folder = contentFolderService.Get(contentFolderId);

            if (folder == null || !folder.IsEnabled)
            {
                return(HttpNotFound());
            }
            pageResourceManager.InsertTitlePart(folder.FolderName);
            pageResourceManager.SetMeta(new MetaEntry("Title", folder.METATitle));
            pageResourceManager.SetMetaOfKeywords(folder.METAKeywords);
            pageResourceManager.SetMetaOfDescription(folder.METADescription);

            PagingDataSet <ContentItem> contentItems = contentItemService.GetContentItemsSortBy(ContentItemSortBy.ReleaseDate_Desc, null, contentFolderId, true, null, pageSize, pageIndex);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_List", contentItems));
            }
            ViewData["currentFolder"] = folder;

            ViewData["allParentContentFolders"] = folder.Parents;
            //设置路由数据中的当前导航Id
            RouteData.Values["CurrentNavigationId"] = NavigationService.GenerateDynamicNavigationId(folder.Parents.FirstOrDefault() == null ? contentFolderId : folder.Parents.First().ContentFolderId);

            return(View(contentItems));
        }
Example #4
0
        public async Task <ActionResult> FileProperties(string tabId, int parentId, string id, string successfulActionCode)
        {
            var file  = ContentFolderService.GetFile(parentId, id);
            var model = FileViewModel.Create(file, tabId, parentId, false);

            model.SuccesfulActionCode = successfulActionCode;
            return(await JsonHtml("FileProperties", model));
        }
Example #5
0
        public async Task <ActionResult> Properties(string tabId, int parentId, int id, string successfulActionCode)
        {
            var folder = ContentFolderService.Read(id);
            var model  = ContentFolderViewModel.Create(folder, tabId, parentId);

            model.SuccesfulActionCode = successfulActionCode;
            return(await JsonHtml("FolderProperties", model));
        }
Example #6
0
        public JsonResult TestLibraryFileDownload(int id, string fileName, string entityTypeCode)
        {
            var pathInfo = entityTypeCode == EntityTypeCode.ContentFile ? ContentFolderService.GetPathInfo(id) : SiteFolderService.GetPathInfo(id);

            if (pathInfo == null)
            {
                var formatString = entityTypeCode == EntityTypeCode.ContentFile ? LibraryStrings.ContentFolderNotExists : LibraryStrings.SiteFolderNotExists;
                return(Json(new { proceed = false, msg = string.Format(formatString, id) }, JsonRequestBehavior.AllowGet));
            }

            return(GetTestFileDownloadResult(pathInfo, fileName, false));
        }
Example #7
0
        public JsonResult _FolderPath(int folderId)
        {
            var folder = ContentFolderService.GetById(folderId);

            return(Json(new
            {
                success = true,
                path = folder.PathInfo.Path,
                url = folder.PathInfo.Url,
                libraryPath = folder.OsSpecificPath
            }));
        }
Example #8
0
        public async Task <ActionResult> FileProperties(string tabId, int parentId, string id, IFormCollection collection)
        {
            var file  = ContentFolderService.GetFile(parentId, id);
            var model = FileViewModel.Create(file, tabId, parentId, false);

            await TryUpdateModelAsync(model);

            if (ModelState.IsValid)
            {
                ContentFolderService.SaveFile(model.File);
                return(Redirect("FileProperties", new { tabId, parentId, id = model.Id, successfulActionCode = ActionCode.UpdateContentFile }));
            }

            return(await JsonHtml("FileProperties", model));
        }
        public ActionResult New(string tabId, int parentId, int id, FormCollection collection)
        {
            var folder = ContentFolderService.NewForSave(parentId, id);
            var model  = ContentFolderViewModel.Create(folder, tabId, parentId);

            TryUpdateModel(model);
            model.Validate(ModelState);
            if (ModelState.IsValid)
            {
                model.Data = ContentFolderService.Save(model.Data);
                PersistResultId(model.Data.Id);
                return(Redirect("Properties", new { tabId, parentId, id = model.Data.Id, successfulActionCode = ActionCode.SaveSiteFolder }));
            }

            return(JsonHtml("FolderProperties", model));
        }
Example #10
0
        public JsonResult _FolderPath(int folderId)
        {
            var folder = ContentFolderService.GetById(folderId);

            return(new JsonResult
            {
                Data = new
                {
                    success = true,
                    path = folder.PathInfo.Path,
                    url = folder.PathInfo.Url,
                    libraryPath = folder.Path
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #11
0
        public async Task <ActionResult> Properties(string tabId, int parentId, int id, IFormCollection collection)
        {
            var folder = ContentFolderService.ReadForUpdate(id);
            var model  = ContentFolderViewModel.Create(folder, tabId, parentId);

            await TryUpdateModelAsync(model);

            if (ModelState.IsValid)
            {
                model.Data = ContentFolderService.Update(model.Data);
                PersistResultId(model.Data.Id);
                return(Redirect("Properties", new { tabId, parentId, id = model.Data.Id, successfulActionCode = ActionCode.UpdateSite }));
            }

            return(await JsonHtml("FolderProperties", model));
        }
        /// <summary>
        /// Делает невидимыми некоторые элементы контекстного меню для корневого Content Folder
        /// </summary>
        public static IEnumerable <BackendActionStatus> ResolveStatusesForContentFolder(this IEnumerable <BackendActionStatus> statuses, int entityId)
        {
            var folder = ContentFolderService.GetById(entityId);

            if (!folder.ParentId.HasValue)
            {
                var codes = new[] { ActionCode.ContentFolderProperties, ActionCode.RemoveContentFolder };
                foreach (var status in statuses)
                {
                    if (codes.Contains(status.Code))
                    {
                        status.Visible = false;
                    }
                }
            }

            return(statuses);
        }
Example #13
0
        protected override IEnumerable<Navigation> GetDynamicNavigations(string presentAreaKey, long ownerId = 0)
        {
            List<Navigation> navigations = new List<Navigation>();

            if (presentAreaKey != PresentAreaKeysOfBuiltIn.Channel)
                return navigations;

            ContentFolderService contentFolderService = new ContentFolderService();
            IEnumerable<ContentFolder> contentFolders = contentFolderService.GetRootFolders();

            if (contentFolders != null)
            {
                foreach (var contentFolder in contentFolders)
                {
                    if (!contentFolder.IsEnabled)
                        continue;
                    string url = SiteUrls.Instance().FolderDetail(contentFolder.ContentFolderId);
                    if (contentFolder.IsLink)
                        url = contentFolder.LinkUrl;

                    int navigationId = NavigationService.GenerateDynamicNavigationId(contentFolder.ContentFolderId);
                    Navigation navigation = new Navigation()
                    {
                        ApplicationId = ApplicationId,
                        Depth = 1,
                        NavigationId = navigationId,
                        NavigationText = contentFolder.FolderName,
                        ParentNavigationId = 10101501,
                        IsEnabled = true,
                        NavigationTarget = "_self",
                        NavigationUrl = url,
                        PresentAreaKey = PresentAreaKeysOfBuiltIn.Channel,
                        DisplayOrder = (int)contentFolder.DisplayOrder + 90000000
                    };
                    if (contentFolder.IsLink && contentFolder.IsLinkToNewWindow)
                        navigation.NavigationTarget = "_blank";
                    navigations.Add(navigation);
                }
            }

            return navigations;
        }
Example #14
0
        /// <summary>
        /// 获取子级栏目
        /// </summary>
        /// <returns></returns>
        public JsonResult GetChildContentFolders(string contentTypeKey = null, int exceptFolderId = 0, bool?onlyModerated = null)
        {
            int parentId = Request.QueryString.Get <int>("Id", 0);

            var folder = new ContentFolderService().Get(parentId);

            if (folder == null || folder.Children == null)
            {
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
            var folders = folder.Children;

            if (!string.IsNullOrEmpty(contentTypeKey))
            {
                folders = folders.Where(n => n.ContentTypeKeys.Split(',').Contains(contentTypeKey));
            }
            if (onlyModerated.HasValue && onlyModerated.Value)
            {
                folders = folders.Where(n => authorizer.CMS_ManageContentFolder(n));
            }
            return(Json(folders.Where(n => n.ContentFolderId != exceptFolderId && !n.IsLink).Select(n => new { id = n.ContentFolderId, name = n.FolderName }), JsonRequestBehavior.AllowGet));
        }
Example #15
0
 public FileResult _ContentFileThumbnail(int folderId, string fileName)
 {
     return(GetThumbnailResult(ContentFolderService.GetPath(folderId, fileName)));
 }
Example #16
0
        public ActionResult Remove(int id)
        {
            var result = ContentFolderService.Remove(id);

            return(JsonMessageResult(result));
        }
Example #17
0
 public ActionResult RemovePreAction(int parentId, int id) => Json(ContentFolderService.RemovePreAction(id));
Example #18
0
        public JsonResult GetLibraryImageProperties(int id, string fileName, string entityTypeCode)
        {
            var pathInfo = entityTypeCode == EntityTypeCode.ContentFile ? ContentFolderService.GetPathInfo(id) : SiteFolderService.GetPathInfo(id);

            return(GetFileProperties(pathInfo, fileName, new FilePropertiesOptions()));
        }
        /// <summary>
        /// 栏目详细页
        /// </summary>
        public ActionResult FolderDetail(int contentFolderId, int pageSize = 15, int pageIndex = 1)
        {
            var contentFolderService = new ContentFolderService();
            var folder = contentFolderService.Get(contentFolderId);
            if (folder == null || !folder.IsEnabled)
            {
                return HttpNotFound();
            }
            pageResourceManager.InsertTitlePart(folder.FolderName);
            pageResourceManager.SetMeta(new MetaEntry("Title", folder.METATitle));
            pageResourceManager.SetMetaOfKeywords(folder.METAKeywords);
            pageResourceManager.SetMetaOfDescription(folder.METADescription);

            PagingDataSet<ContentItem> contentItems = contentItemService.GetContentItemsSortBy(ContentItemSortBy.ReleaseDate_Desc, null, contentFolderId, true, null, pageSize, pageIndex);
            if (Request.IsAjaxRequest())
                return PartialView("_List", contentItems);
            ViewData["currentFolder"] = folder;

            ViewData["allParentContentFolders"] = folder.Parents;
            //设置路由数据中的当前导航Id
            RouteData.Values["CurrentNavigationId"] = NavigationService.GenerateDynamicNavigationId(folder.Parents.FirstOrDefault() == null ? contentFolderId : folder.Parents.First().ContentFolderId);

            return View(contentItems);
        }
        /// <summary>
        /// 获取子级栏目
        /// </summary>
        /// <returns></returns>
        public JsonResult GetChildContentFolders(string contentTypeKey = null, int exceptFolderId = 0, bool? onlyModerated = null)
        {
            int parentId = Request.QueryString.Get<int>("Id", 0);

            var folder = new ContentFolderService().Get(parentId);
            if (folder == null || folder.Children == null)
                return Json(new { }, JsonRequestBehavior.AllowGet);
            var folders = folder.Children;
            if (!string.IsNullOrEmpty(contentTypeKey))
                folders = folders.Where(n => n.ContentTypeKeys.Split(',').Contains(contentTypeKey));
            if (onlyModerated.HasValue && onlyModerated.Value)
            {
                folders = folders.Where(n => authorizer.CMS_ManageContentFolder(n));
            }
            return Json(folders.Where(n => n.ContentFolderId != exceptFolderId && !n.IsLink).Select(n => new { id = n.ContentFolderId, name = n.FolderName }), JsonRequestBehavior.AllowGet);
        }
Example #21
0
        public ActionResult MultipleRemoveFiles(int parentId, [FromBody] SelectedStringItemsViewModel model)
        {
            var result = ContentFolderService.RemoveFiles(parentId, model.Ids);

            return(Json(result));
        }
        public ActionResult ManageContentItems(AuditStatus? auditStatus = null, int? folderId = null, string subjectKeyWord = null, string tagNameKeyword = null, string userId = null, DateTime? minDate = null, DateTime? maxDate = null, int pageSize = 20, int pageIndex = 1)
        {
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return Redirect(SiteUrls.Instance().Login(true));
            long? id = null;
            if (!string.IsNullOrEmpty(userId))
            {
                userId = userId.TrimStart(',').TrimEnd(',');
                if (!string.IsNullOrEmpty(userId))
                {
                    id = long.Parse(userId);
                }
            }
            ViewData["userId"] = id;
            var contentFolderService = new ContentFolderService();
            if (folderId.HasValue && folderId.Value > 0)
            {
                ContentFolder contentFolder = contentFolderService.Get(folderId.Value);
                if (!authorizer.CMS_ManageContentFolder(contentFolder))
                {
                    return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = string.Format("您没有权限管理 {0} !", contentFolder == null ? "" : contentFolder.FolderName),
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }
            else
            {
                //判断用户是否为栏目管理员
                if (!authorizer.CMS_ManageContentItemsForChannel())
                {
                    return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "您没有权限在前台管理资讯",
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }

            var contentTypes = new MetadataService().GetContentTypes(true);
            ViewData["ContentTypes"] = contentTypes;
            long? moderatorUserId = null;
            if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
                moderatorUserId = currentUser.UserId;
            PagingDataSet<ContentItem> items = contentItemService.GetContentItemsForAdmin(auditStatus, subjectKeyWord, folderId, true, tagNameKeyword: tagNameKeyword, userId: id, moderatorUserId: moderatorUserId, minDate: minDate, maxDate: maxDate, pageSize: pageSize, pageIndex: pageIndex);
            pageResourceManager.InsertTitlePart("资讯管理");
            RouteData.Values["CurrentNavigationId"] = "10101501";
            return View(items);
        }
        /// <summary>
        /// 将EditModel转换成数据库实体
        /// </summary>
        public ContentItem AsContentItem(System.Web.HttpRequestBase Request)
        {
            ContentItem contentItem = null;
            if (this.ContentItemId > 0)
            {
                contentItem = new ContentItemService().Get(this.ContentItemId);
            }
            else
            {
                contentItem = new ContentItem();
                contentItem.Author = UserContext.CurrentUser == null ? "" : UserContext.CurrentUser.DisplayName;
                contentItem.IP = WebUtility.GetIP();
                contentItem.UserId = UserContext.CurrentUser == null ? 0 : UserContext.CurrentUser.UserId;
                contentItem.ContentTypeId = this.ContentTypeId;
            }

            if (this.ContentFolderId > 0)
            {
                ContentFolder folder = new ContentFolderService().Get(this.ContentFolderId);
                if (folder != null)
                {
                    contentItem.ContentFolderId = this.ContentFolderId;
                    if (this.AdditionalProperties == null)
                        this.AdditionalProperties = new Dictionary<string, object>();
                    IEnumerable<ContentTypeColumnDefinition> contentTypeColumnDefinitions = new MetadataService().GetColumnsByContentTypeId(this.ContentTypeId);
                    foreach (var item in contentTypeColumnDefinitions)
                    {
                        object value = null;

                        switch (item.DataType)
                        {
                            case "int":
                            case "long":
                                value = Request.Form.Get<long>(item.ColumnName, 0);
                                break;
                            case "datetime":
                                value = Request.Form.Get<DateTime>(item.ColumnName, DateTime.MinValue);
                                break;

                            case "bool":
                                value = Request.Form.Get<bool>(item.ColumnName, false);
                                break;

                            default:
                                value = Request.Form.Get<string>(item.ColumnName, string.Empty);
                                break;
                        }

                        if (this.AdditionalProperties.ContainsKey(item.ColumnName))
                            this.AdditionalProperties[item.ColumnName] = value;
                        else
                            this.AdditionalProperties.Add(item.ColumnName, value);
                    }
                }
            }
            contentItem.AdditionalProperties = this.AdditionalProperties;
            contentItem.IsEssential = false;
            contentItem.IsLocked = false;

            contentItem.IsGlobalSticky = this.IsGlobalSticky;
            if (this.GlobalStickyDate.CompareTo(DateTime.MinValue) > 0)
                contentItem.GlobalStickyDate = this.GlobalStickyDate;
            contentItem.IsFolderSticky = this.IsFolderSticky;
            if (this.FolderStickyDate.CompareTo(DateTime.MinValue) > 0)
                contentItem.FolderStickyDate = this.FolderStickyDate;
            contentItem.DisplayOrder = this.DisplayOrder;
            contentItem.FeaturedImageAttachmentId = this.FeaturedImageAttachmentId;
            contentItem.LastModified = DateTime.UtcNow;
            contentItem.Title = this.Title;
            if (this.ReleaseDate.CompareTo(DateTime.MinValue) > 0)
                contentItem.ReleaseDate = this.ReleaseDate.ToUniversalTime();
            //摘要
            contentItem.Summary = this.Summary ?? string.Empty;
            if (this.TrimBodyAsSummary)
            {
                string summary = HtmlUtility.TrimHtml(Request.Form.Get<string>("Body", string.Empty), TextLengthSettings.TEXT_DESCRIPTION_MAXLENGTH);
                contentItem.Summary = summary;
            }

            if (contentItem.AdditionalProperties.ContainsKey("AutoPage"))
            {
                bool autoPage = Request.Form.Get<bool>("AutoPage", false);
                int pageLength = Request.Form.Get<int>("PageLength", 1000);
                string body = contentItem.AdditionalProperties.Get<string>("Body", string.Empty);
                if (autoPage)
                {
                    pageLength = pageLength > 0 ? pageLength : 1000;
                    if (!string.IsNullOrEmpty(body))
                    {
                        body = body.Replace(ContentPages.PageSeparator, "");
                        contentItem.AdditionalProperties["Body"] = string.Join(ContentPages.PageSeparator, ContentPages.GetPageContentForStorage(body, pageLength, true).ToArray());
                    }
                }
                else
                {
                    pageLength = 0;
                    body = body.Replace(ContentPages.PageSeparator, "");
                    contentItem.AdditionalProperties["Body"] = body;
                    contentItem.AdditionalProperties["pageLength"] = pageLength;
                }
            }

            if (contentItem.AdditionalProperties.ContainsKey("Editor"))
            {
                string editor = contentItem.AdditionalProperties.Get<string>("Editor", string.Empty);
                if (string.IsNullOrEmpty(editor))
                    contentItem.AdditionalProperties["Editor"] = contentItem.ContentFolder.Editor;
            }

            if (contentItem.FeaturedImageAttachmentId > 0)
            {
                AttachmentService<Attachment> attachmentService = new AttachmentService<Attachment>(TenantTypeIds.Instance().ContentItem());
                Attachment attachment = attachmentService.Get(contentItem.FeaturedImageAttachmentId);
                if (attachment != null)
                {
                    contentItem.FeaturedImage = attachment.GetRelativePath() + "\\" + attachment.FileName;
                }
                else
                {
                    contentItem.FeaturedImageAttachmentId = 0;
                }
            }
            else
            {
                contentItem.FeaturedImage = string.Empty;
            }
            return contentItem;
        }
Example #24
0
        public ActionResult MultipleRemoveFiles(int parentId, string[] IDs)
        {
            var result = ContentFolderService.RemoveFiles(parentId, IDs);

            return(Json(result));
        }
Example #25
0
        public ContentFolder AsContentFolder()
        {
            ContentFolder contentFolder = new ContentFolder();

            if (this.ContentFolderId > 0)
                contentFolder = new ContentFolderService().Get(this.ContentFolderId);

            contentFolder.FolderName = this.FolderName;

            contentFolder.Description = this.Description ?? string.Empty;

            contentFolder.IsEnabled = this.IsEnabled;

            contentFolder.IsAsNavigation = this.IsAsNavigation;

            contentFolder.ParentId = this.ParentId.HasValue ? this.ParentId.Value : 0;

            contentFolder.Page_Detail = this.Page_Detail ?? string.Empty;

            contentFolder.Page_List = this.Page_List ?? string.Empty;

            contentFolder.IsLinkToNewWindow = this.IsLinkToNewWindow;

            contentFolder.LinkUrl = this.LinkUrl ?? string.Empty;

            contentFolder.IsLink = this.IsLink;

            contentFolder.ContentTypeKeys = string.Join(",", this.ContentTypeKeys);

            contentFolder.Icon = this.icon ?? string.Empty;

            contentFolder.METATitle = this.METATitle ?? string.Empty;
            contentFolder.METAKeywords = this.METAKeywords ?? string.Empty;
            contentFolder.METADescription = this.METADescription ?? string.Empty;
            contentFolder.NeedAuditing = this.NeedAuditing;
            contentFolder.Editor = this.Editor ?? string.Empty;
            return contentFolder;
        }
Example #26
0
        public ActionResult ManageContentItems(AuditStatus?auditStatus = null, int?folderId = null, string subjectKeyWord = null, string tagNameKeyword = null, string userId = null, DateTime?minDate = null, DateTime?maxDate = null, int pageSize = 20, int pageIndex = 1)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(Redirect(SiteUrls.Instance().Login(true)));
            }
            long?id = null;

            if (!string.IsNullOrEmpty(userId))
            {
                userId = userId.TrimStart(',').TrimEnd(',');
                if (!string.IsNullOrEmpty(userId))
                {
                    id = long.Parse(userId);
                }
            }
            ViewData["userId"] = id;
            var contentFolderService = new ContentFolderService();

            if (folderId.HasValue && folderId.Value > 0)
            {
                ContentFolder contentFolder = contentFolderService.Get(folderId.Value);
                if (!authorizer.CMS_ManageContentFolder(contentFolder))
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = string.Format("您没有权限管理 {0} !", contentFolder == null ? "" : contentFolder.FolderName),
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    })));
                }
            }
            else
            {
                //判断用户是否为栏目管理员
                if (!authorizer.CMS_ManageContentItemsForChannel())
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "您没有权限在前台管理资讯",
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    })));
                }
            }

            var contentTypes = new MetadataService().GetContentTypes(true);

            ViewData["ContentTypes"] = contentTypes;
            long?moderatorUserId = null;

            if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
            {
                moderatorUserId = currentUser.UserId;
            }
            PagingDataSet <ContentItem> items = contentItemService.GetContentItemsForAdmin(auditStatus, subjectKeyWord, folderId, true, tagNameKeyword: tagNameKeyword, userId: id, moderatorUserId: moderatorUserId, minDate: minDate, maxDate: maxDate, pageSize: pageSize, pageIndex: pageIndex);

            pageResourceManager.InsertTitlePart("资讯管理");
            RouteData.Values["CurrentNavigationId"] = "10101501";
            return(View(items));
        }