Files
Orchard/src/Orchard.Web/Packages/Orchard.Blogs/Services/BlogService.cs
ErikPorter 4dca80d2e9 Fixed bug #15041
--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041951
2009-11-23 21:22:29 +00:00

37 lines
1.3 KiB
C#

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;
public BlogService(IContentManager contentManager, IRepository<BlogRecord> repository) {
_contentManager = contentManager;
_repository = repository;
}
public Blog Get(string slug) {
BlogRecord record = _repository.Get(br => br.Slug == slug && br.Enabled);
return record != null ?_contentManager.Get<Blog>(record.Id) : null;
}
public IEnumerable<Blog> Get() {
IEnumerable<BlogRecord> blogs = _repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
return blogs.Select(br => _contentManager.Get<Blog>(br.Id));
}
public Blog CreateBlog(CreateBlogParams parameters) {
return _contentManager.Create<Blog>("blog", init => {
init.Record.Name = parameters.Name;
init.Record.Slug = parameters.Slug;
init.Record.Enabled = parameters.Enabled;
});
}
}
}