public ActionResult File(string permalink) { if (!permalink.StartsWith("/")) { permalink = "/" + permalink; } var request = new SiteContentRequest() { Permalink = permalink }; var content = _cmsService.GetSiteContents(request) .Where(s => s.SiteContentStatusID == (int)ContentStatus.Published || s.SiteContentStatusID == (int)ContentStatus.Draft) .FirstOrDefault(s => s.SiteContentTypeID == (int)ContentType.File); if (content == null || content.FileID == null) { return(new EmptyResult()); } var file = _fileService.DownloadFile(new FileRequest { FileID = content.FileID.Value }); return(new FileServiceResult(file)); }
public void DeleteContentVersion(int id, int versionId) { var request = new SiteContentRequest() { SiteContentID = id, IncludeProfileTypes = true, IncludeAffiliates = true, IncludeVersions = true }; var content = _cmsService.GetSiteContent(request); if (content == null) { throw new Exception("Invalid Site Content ID"); } var version = content.Versions.FirstOrDefault(v => v.SiteContentVersionID == versionId); if (version != null) { content.Versions.Remove(version); _cmsService.SaveSiteContent(ref content, CurrentUser.UserID); } }
public SiteContent GetContent(int id) { var request = new SiteContentRequest() { SiteContentID = id, IncludeSiteContentStatus = true, IncludeSiteContentType = true, IncludeSiteDocumentType = true, IncludeProfileTypes = true, IncludeAffiliates = true, IncludeSite = true, IncludeSiteTemplates = true, IncludeVersions = true, IncludeFileInfo = true, IncludeKnowledgeLibraries = true }; var content = _cmsService.GetSiteContent(request); if (content == null) { throw new Exception("Invalid Site Content ID"); } return(content); }
public dynamic GetPages([FromUri] SearchContentRequest searchRequest) { var request = new SiteContentRequest() { SiteID = searchRequest.SiteID, ContentTypes = new List <ContentType>() { ContentType.ContentPage, ContentType.StaticPage }, IncludeSiteContentStatus = true, IncludeSiteContentType = true }; if (!string.IsNullOrWhiteSpace(searchRequest.SearchText)) { request.SearchTerms.Add(searchRequest.SearchText); } if (searchRequest.SiteContentStatusID > 0) { request.ContentStatuses.Add((ContentStatus)searchRequest.SiteContentStatusID); } else { request.ContentStatuses.AddRange(new[] { ContentStatus.Published, ContentStatus.Draft }); } var content = _cmsService.GetSiteContents(request).OrderBy(s => s.SiteContentParentID).ThenBy(s => s.SortOrder).ToList(); return(content.Select(s => new { s.SiteContentID, s.SiteContentParentID, s.Title, s.TitlePath, s.SiteID, s.SiteContentStatus.StatusDescription, s.SiteContentType.ContentTypeDescription, s.SiteContentType.ContentTypeName, s.ModifyDateUtc, s.Permalink, VersionCount = s.Versions.Count })); }
public ActionResult Preview(int contentId, int versionId) { var request = new SiteContentRequest() { SiteContentID = contentId, IncludeSite = true, IncludeSiteTemplates = true }; var content = _cmsService.GetSiteContent(request); if (content == null) { throw new Exception("Invalid Content ID"); } var version = content.Versions.FirstOrDefault(v => v.SiteContentVersionID == versionId); if (version == null) { throw new Exception("Invalid Version ID"); } // Now set the site map (so we can render any menus, etc.) var siteMap = _cmsService.GetSiteMap(content.SiteID, CurrentUser.ProfileTypeID, CurrentUser.AffiliateID); SetSiteMap(siteMap); var viewModel = new ContentViewModel() { Title = string.Format("{0} | {1}", content.Site.SiteName, content.Title), PageTitle = content.Title, LayoutPath = version.SiteTemplate != null ? version.SiteTemplate.LayoutPath : "~/Views/Shared/Layouts/_PortalDefault.cshtml", Html = version.ContentText }; return(View("~/Views/Content/Index.cshtml", viewModel)); }
public dynamic GetFiles([FromUri] SearchContentRequest searchRequest) { var request = new SiteContentRequest() { SiteID = searchRequest.SiteID, ContentTypes = new List <ContentType>() { ContentType.File }, ContentStatuses = new List <ContentStatus>() { ContentStatus.Published }, IncludeSiteDocumentType = true, IncludeKnowledgeLibraries = true, IncludeFileInfo = true }; if (!string.IsNullOrWhiteSpace(searchRequest.SearchText)) { request.SearchTerms.Add(searchRequest.SearchText); } var content = _cmsService.GetSiteContents(request).OrderByDescending(s => s.ModifyDateUtc).ToList(); return(content.Select(s => new { s.SiteContentID, s.Title, s.SiteID, FileName = s.FileInfo != null ? s.FileInfo.Name : null, FileSize = s.FileInfo != null ? s.FileInfo.SizeKiloBytes : 0, FileType = s.FileInfo != null ? s.FileInfo.Extension.TrimStart('.').ToUpper() : null, KnowledgeLibrary = s.KnowledgeLibrary != null ? "Yes" : null, s.ModifyDateUtc, s.Permalink })); }
public JsonNetResult JsonSearch(string searchText, string siteName, int textMaxChars = 100) { var content = new List <SiteContentViewModel>(); if (!string.IsNullOrWhiteSpace(searchText)) { var searchTerms = Regex.Matches(searchText, @"([\""\''])(.+?)([\""\''])|[^ ,]+") .Cast <Match>() .Select(m => m.Groups[2].Success ? m.Groups[2].Value : m.Groups[0].Value) .ToArray(); var request = new SiteContentRequest() { SearchTerms = searchTerms.ToList(), ContentDocumentTypes = Settings.SearchableDocumentTypes.ToList(), SiteName = siteName != "All" ? siteName : null, ProfileTypeID = AssistedUser.ProfileTypeID, AffiliateID = AssistedUser.AffiliateID, MaxContentCharacters = textMaxChars }; content = _cmsService.SearchSiteContents(request).ToList(); } return(new JsonNetResult(content.OrderByDescending(r => r.SearchRank).ThenBy(r => r.Title).Select(r => new { r.Title, Text = r.ContentHtml, r.SiteName, SiteIconCssClass = r.SiteName.ToLower().Replace(" ", "-"), ItemCssClass = r.ContentType == ContentType.File ? "document" : "link", r.Url, ShortUrl = StripProtocol(r.Url), UrlTarget = r.ContentType == ContentType.File ? "_blank" : "_self" }))); }
public IEnumerable <SiteContentViewModel> SearchSiteContents(SiteContentRequest request) { var proxy = _cmsService.CreateProxy(); return(proxy.SearchSiteContents(request)); }
public SiteContent GetSiteContent(SiteContentRequest request) { var proxy = _cmsService.CreateProxy(); return(proxy.GetSiteContent(request)); }
public IEnumerable <SiteContent> GetSiteContents(SiteContentRequest request) { var proxy = _cmsService.CreateProxy(); return(proxy.GetSiteContents(request)); }
public IEnumerable <SiteContentViewModel> SearchSiteContents(SiteContentRequest request) { if (request.SearchTerms.IsNullOrEmpty()) { return(null); } var query = GetSiteContentInternal(request.ProfileTypeID, request.AffiliateID).Where(s => s.IsPublished()); if (!request.ContentDocumentTypes.IsNullOrEmpty()) { query = query.Where(s => request.ContentDocumentTypes.Contains((ContentDocumentType)s.SiteDocumentTypeID)); } if (request.SiteID.HasValue && request.SiteID > 0) { query = query.Where(s => s.SiteID == request.SiteID); } if (!string.IsNullOrWhiteSpace(request.SiteName)) { query = query.Where(s => s.Site.SiteName.Equals(request.SiteName, StringComparison.InvariantCultureIgnoreCase)); } var results = FilterSearchResults(query.ToList()) .Where(item => item.Title.Contains(request.SearchTerms.ToArray()) || item.ContentHtml.StripTags().Contains(request.SearchTerms.ToArray()) || item.Description.Contains(request.SearchTerms.ToArray())).ToList(); return(results.Select(item => { var searchRank = request.SearchTerms.Sum(term => item.Title.CountOccurrencesOf(term) * 50 + item.Description.CountOccurrencesOf(term) * 2 + item.ContentHtml.CountOccurrencesOf(term) * 1); var text = item.ContentHtml; if (!string.IsNullOrEmpty(text) && request.MaxContentCharacters.HasValue) { var strippedText = Regex.Replace(text, @"\t|\n|\r|<br>|<br />|<br/>|<p>|</p>", " ").StripTags().Trim(); var retVal = strippedText.SubstringByWord(request.MaxContentCharacters.Value); if (strippedText.Length > retVal.Length && retVal[retVal.Length - 1] != '.') { retVal += " ..."; } text = retVal; } return new SiteContentViewModel() { Title = item.Title, ContentHtml = text, SiteName = item.Site.SiteName, ContentType = item.ContentType, DocumentType = item.DocumentType, Url = item.Url, SearchRank = searchRank }; })); }
public SiteContent GetSiteContent(SiteContentRequest request) { return(GetSiteContents(request).FirstOrDefault()); }
public IEnumerable <SiteContent> GetSiteContents(SiteContentRequest request) { var query = _cmsRepository.GetAll <SiteContent>() .Include("Versions") .Include("Versions.Affiliates"); if (request.SiteContentID.HasValue) { query = query.Where(s => s.SiteContentID == request.SiteContentID.Value); } if (request.SiteID.HasValue) { query = query.Where(s => s.SiteID == request.SiteID.Value); } if (!string.IsNullOrEmpty(request.Permalink)) { if (!request.Permalink.StartsWith("/")) { request.Permalink = "/" + request.Permalink; } query = query.Where(s => s.Permalink == request.Permalink); } if (!request.ContentStatuses.IsNullOrEmpty()) { query = query.Where(s => request.ContentStatuses.Contains((ContentStatus)s.SiteContentStatusID)); } if (!request.ContentTypes.IsNullOrEmpty()) { query = query.Where(s => request.ContentTypes.Contains((ContentType)s.SiteContentTypeID)); } if (request.IncludeSite) { query = query.Include("Site"); } if (request.IncludeSite && request.IncludeSiteContents) { query = query.Include("Site.SiteContents"); } if (request.IncludeSite && request.IncludeSiteTemplates) { query = query.Include("Site.SiteTemplates"); } if (request.IncludeProfileTypes) { query = query.Include("ProfileTypes"); } if (request.IncludeAffiliates) { query = query.Include("Affiliates"); } if (request.IncludeSiteDocumentType) { query = query.Include("SiteDocumentType"); } if (request.IncludeSiteContentType) { query = query.Include("SiteContentType"); } if (request.IncludeSiteContentStatus) { query = query.Include("SiteContentStatus"); } if (request.IncludeSiteTemplates) { query = query.Include("Versions.SiteTemplate"); } if (request.IncludeKnowledgeLibraries) { query = query.Include("KnowledgeLibraries"); } if (request.IncludeSiteContentHistories) { query = query.Include("SiteContentHistories"); } if (request.IncludeParents) { query = query.Include("Parent"); } if (request.IncludeFileInfo) { query = query.Include("FileInfo"); } if (!request.SearchTerms.IsNullOrEmpty()) { query = query.AsNoTracking().ToList() .Where(item => item.Title.Contains(request.SearchTerms.ToArray()) || (item.DefaultContentVersion != null && item.DefaultContentVersion.ContentText.StripTags().Contains(request.SearchTerms.ToArray())) || item.Description.Contains(request.SearchTerms.ToArray())) .AsQueryable(); } return(query.AsNoTracking().ToList()); }