Esempio n. 1
0
        public PagedResults <FileView> GetFiles(PagedRequest request = null)
        {
            var query = _database.Files.Where(x => !x.IsDeleted);

            request = request ?? new PagedRequest();
            request.Cleanup();

            if (!string.IsNullOrWhiteSpace(request.Filter))
            {
                query = request.FilterValues?.Any() == true
                                        ? query.Where(request.Filter, request.FilterValues)
                                        : query.Where(request.Filter);
            }

            query = query.OrderBy(string.IsNullOrWhiteSpace(request.Order) ? "Name" : request.Order);
            return(GetPagedResults(query, request, x => new FileView
            {
                Id = x.Id,
                ModifiedOn = x.ModifiedOn,
                Name = x.Name,
                NameForLink = PageView.ConvertTitleForLink(x.Name),
                Size = x.Size / 1024 + " kb",
                Type = x.Type
            }));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public FileView ToView(bool includeData = false)
        {
            var response = new FileView
            {
                Id          = Id,
                ModifiedOn  = ModifiedOn,
                Name        = Name,
                NameForLink = PageView.ConvertTitleForLink(Name),
                Size        = Size / 1024 + " kb",
                Type        = Type
            };

            if (includeData)
            {
                response.Data = new byte[Data.Length];
                Array.Copy(Data, response.Data, Data.Length);
            }

            return(response);
        }
Esempio n. 4
0
 public PageView ToView(MarkupConverter converter = null, bool includeDetails = true)
 {
     return(new PageView
     {
         ApprovalStatus = ApprovalStatus,
         Id = PageId,
         CreatedBy = CreatedBy.DisplayName,
         CreatedOn = CreatedOn,
         EditingBy = EditingOn > DateTime.UtcNow.Subtract(Constants.EditingTimeout) ? (EditingBy?.DisplayName ?? string.Empty) : string.Empty,
         Files = new List <FileView>(),
         Html = includeDetails ? converter?.ToHtml(Text) ?? string.Empty : string.Empty,
         IsPublished = IsPublished,
         LastModified = DateTime.UtcNow.Subtract(CreatedOn).ToTimeAgo(),
         Pages = new List <PageReference>(),
         Tags = SplitTags(Tags),
         Text = includeDetails ? Text : string.Empty,
         Title = Title,
         TitleForLink = PageView.ConvertTitleForLink(Title)
     });
 }
Esempio n. 5
0
        public PageHistoryView ToHistoryView(bool guestView)
        {
            var versionQuery = Page.Versions.Where(x => x.Id <= Id);

            if (guestView)
            {
                versionQuery = versionQuery.Where(x => x.IsPublished && x.ApprovalStatus == ApprovalStatus.Approved);
            }

            var versions = versionQuery.OrderByDescending(x => x.Id).ToList();
            var index    = versions.Count;
            var history  = versions.Select(x => x.ToHistorySummaryView(index--)).ToList();

            return(new PageHistoryView
            {
                Id = PageId,
                Title = Title,
                TitleForLink = PageView.ConvertTitleForLink(Title),
                Versions = history
            });
        }
Esempio n. 6
0
 /// <summary>
 /// Gets the internal URL of a page based on the page title.
 /// </summary>
 /// <param name="id"> The page id </param>
 /// <param name="title"> The title of the page </param>
 /// <returns> An absolute path to the page. </returns>
 public virtual string GetInternalUrlForTitle(int id, string title)
 {
     return($"/Page/{id}/{PageView.ConvertTitleForLink(title)}");
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the internal URL of a page based on the file name.
 /// </summary>
 /// <param name="id"> The file id. </param>
 /// <param name="name"> The name of the file. </param>
 /// <returns> An absolute path to the page. </returns>
 public virtual string GetInternalUrlForFileName(int id, string name)
 {
     return($"/File/{id}/{PageView.ConvertTitleForLink(name)}");
 }