2009-11-20 23:31:49 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using Orchard.Blogs.Models;
|
|
|
|
using Orchard.Data;
|
|
|
|
using Orchard.Models;
|
|
|
|
|
|
|
|
namespace Orchard.Blogs.Services {
|
|
|
|
public class BlogService : IBlogService {
|
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
private readonly IRepository<BlogRecord> _repository;
|
|
|
|
|
2009-11-21 00:38:41 +00:00
|
|
|
public BlogService(IContentManager contentManager, IRepository<BlogRecord> repository) {
|
2009-11-20 23:31:49 +00:00
|
|
|
_contentManager = contentManager;
|
2009-11-21 00:38:41 +00:00
|
|
|
_repository = repository;
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Blog Get(string slug) {
|
2009-11-21 00:38:41 +00:00
|
|
|
BlogRecord record = _repository.Get(br => br.Slug == slug && br.Enabled);
|
2009-11-23 21:22:29 +00:00
|
|
|
|
|
|
|
return record != null ?_contentManager.Get<Blog>(record.Id) : null;
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<Blog> Get() {
|
2009-11-21 09:47:18 +00:00
|
|
|
IEnumerable<BlogRecord> blogs = _repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
|
2009-11-20 23:31:49 +00:00
|
|
|
|
2009-11-21 09:47:18 +00:00
|
|
|
return blogs.Select(br => _contentManager.Get<Blog>(br.Id));
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Blog CreateBlog(CreateBlogParams parameters) {
|
2009-11-21 09:47:18 +00:00
|
|
|
return _contentManager.Create<Blog>("blog", init => {
|
|
|
|
init.Record.Name = parameters.Name;
|
|
|
|
init.Record.Slug = parameters.Slug;
|
|
|
|
init.Record.Enabled = parameters.Enabled;
|
|
|
|
});
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|