private SearchResultView Create(Document document, ScoreDoc scoreDoc) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (scoreDoc == null) { throw new ArgumentNullException(nameof(scoreDoc)); } EnsureFieldsExist(document); var createdOn = DateTime.UtcNow; if (!DateTime.TryParse(document.GetField("createdon").StringValue, out createdOn)) { createdOn = DateTime.UtcNow; } var title = document.GetField("title").StringValue; return(new SearchResultView { ContentLength = int.Parse(document.GetField("contentlength").StringValue), ContentSummary = document.GetField("contentsummary").StringValue, CreatedBy = document.GetField("createdby").StringValue, CreatedOn = createdOn, Id = int.Parse(document.GetField("id").StringValue), Score = scoreDoc.Score, Tags = PageVersion.SplitTags(document.GetField("tags").StringValue), Title = title }); }
public PageDifferenceView GetPageDifference(int id) { var version = GetAllPagesQuery().FirstOrDefault(x => x.Id == id); if (version == null) { throw new PageNotFoundException("Failed to find the page with that version ID."); } if (IsGuestRequest && (version.ApprovalStatus != ApprovalStatus.Approved || !version.IsPublished)) { throw new PageNotFoundException("Failed to find the page with that version ID."); } var versions = IsGuestRequest ? version.Page.Versions.Where(x => x.IsPublished && x.ApprovalStatus == ApprovalStatus.Approved) : version.Page.Versions; var previous = versions .Where(x => x.Id < version.Id) .OrderByDescending(x => x.Id) .FirstOrDefault(); var response = new PageDifferenceView { Id = version.PageId, LastModified = DateTime.UtcNow.Subtract(version.ModifiedOn).ToTimeAgo(), CreatedBy = version.CreatedBy.DisplayName }; if (previous == null) { response.Html = Converter.ToHtml(version.Text); response.Title = version.Title; response.TitleForLink = PageView.ConvertTitleForLink(version.Title); response.Tags = string.Join(", ", PageVersion.SplitTags(version.Tags)); } else { response.Html = HtmlDiff.Process(Converter.ToHtml(previous.Text), Converter.ToHtml(version.Text)); response.Title = HtmlDiff.Process(Converter.ToHtml(previous.Title), Converter.ToHtml(version.Title)); response.TitleForLink = PageView.ConvertTitleForLink(previous.Title); response.Tags = HtmlDiff.Process(Converter.ToHtml(string.Join(", ", PageVersion.SplitTags(previous.Tags))), Converter.ToHtml(string.Join(", ", PageVersion.SplitTags(version.Tags)))); } return(response); }