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-21 09:17:22 +00:00
|
|
|
return _contentManager.Get<Blog>(record.Id);
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<Blog> Get() {
|
2009-11-21 00:38:41 +00:00
|
|
|
IEnumerable<BlogRecord> blogs =_repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
|
2009-11-20 23:31:49 +00:00
|
|
|
|
|
|
|
return blogs.Select(br => _contentManager.Get(br.Id).As<Blog>());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Blog CreateBlog(CreateBlogParams parameters) {
|
2009-11-21 00:38:41 +00:00
|
|
|
BlogRecord record = new BlogRecord() {Name = parameters.Name, Slug = parameters.Slug, Enabled = parameters.Enabled};
|
2009-11-20 23:31:49 +00:00
|
|
|
|
|
|
|
//TODO: (erikpo) Need an extension method or something for this default behavior
|
2009-11-21 09:17:22 +00:00
|
|
|
Blog blog = _contentManager.New<Blog>("blog");
|
|
|
|
blog.Record = record;
|
|
|
|
_contentManager.Create(blog);
|
2009-11-20 23:31:49 +00:00
|
|
|
|
2009-11-21 09:17:22 +00:00
|
|
|
return blog;
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|