2010-01-08 21:07:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Orchard.Pages.Models;
|
|
|
|
|
using Orchard.Core.Common.Records;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Pages.Services {
|
|
|
|
|
public class PageService : IPageService {
|
|
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
|
|
2010-01-07 23:12:46 +00:00
|
|
|
|
public PageService(IContentManager contentManager) {
|
2010-01-07 01:06:17 +00:00
|
|
|
|
_contentManager = contentManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Page> Get() {
|
2010-01-08 21:07:35 +00:00
|
|
|
|
return Get(PageStatus.All);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Page> Get(PageStatus status) {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PageStatus.All:
|
|
|
|
|
return _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
|
|
|
|
case PageStatus.Published:
|
|
|
|
|
return _contentManager.Query<Page, PageRecord>(VersionOptions.Published).List();
|
|
|
|
|
case PageStatus.Offline:
|
|
|
|
|
IEnumerable<Page> allPages = _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
|
|
|
|
List<Page> offlinePages = new List<Page>();
|
|
|
|
|
foreach (var page in allPages) {
|
|
|
|
|
if (page.ContentItem.VersionRecord.Published == false) {
|
|
|
|
|
offlinePages.Add(page);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return offlinePages;
|
|
|
|
|
default:
|
|
|
|
|
return new List<Page>();
|
|
|
|
|
}
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page Get(string slug) {
|
|
|
|
|
return _contentManager.Query<Page, PageRecord>()
|
|
|
|
|
.Join<RoutableRecord>().Where(rr => rr.Slug == slug)
|
|
|
|
|
.List().FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 21:07:35 +00:00
|
|
|
|
public Page GetLatest(int id) {
|
|
|
|
|
return _contentManager.Get<Page>(id, VersionOptions.Latest);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 23:12:46 +00:00
|
|
|
|
public Page GetPageOrDraft(string slug) {
|
|
|
|
|
Page page = _contentManager.Query<Page, PageRecord>(VersionOptions.Latest)
|
|
|
|
|
.Join<RoutableRecord>().Where(rr => rr.Slug == slug)
|
|
|
|
|
.List().FirstOrDefault();
|
|
|
|
|
return _contentManager.GetDraftRequired<Page>(page.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page New() {
|
|
|
|
|
return _contentManager.New<Page>("page");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page Create(bool publishNow) {
|
|
|
|
|
return _contentManager.Create<Page>("page", publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 01:06:17 +00:00
|
|
|
|
public void Delete(Page page) {
|
2010-01-07 23:12:46 +00:00
|
|
|
|
_contentManager.Remove(page.ContentItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Publish(Page page) {
|
|
|
|
|
_contentManager.Publish(page.ContentItem);
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
2010-01-08 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
public void Unpublish(Page page) {
|
|
|
|
|
//_contentManager.Unpublish(page.ContentItem);
|
|
|
|
|
}
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|