2010-01-15 23:44:22 +00:00
|
|
|
using System.Linq;
|
2009-12-22 01:55:34 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using Orchard.Blogs.Controllers;
|
2010-01-15 23:44:22 +00:00
|
|
|
using Orchard.Blogs.Services;
|
|
|
|
using Orchard.ContentManagement.Handlers;
|
2009-11-24 02:03:13 +00:00
|
|
|
using Orchard.Core.Common.Models;
|
2010-01-15 23:44:22 +00:00
|
|
|
using Orchard.Core.Common.Services;
|
2009-11-20 23:31:49 +00:00
|
|
|
using Orchard.Data;
|
|
|
|
|
|
|
|
namespace Orchard.Blogs.Models {
|
2009-12-22 01:55:34 +00:00
|
|
|
[UsedImplicitly]
|
2009-12-09 22:01:58 +00:00
|
|
|
public class BlogHandler : ContentHandler {
|
2010-01-15 23:44:22 +00:00
|
|
|
public BlogHandler(IRepository<BlogRecord> repository, IBlogService blogService,
|
|
|
|
IRoutableService routableService) {
|
2009-12-22 01:55:34 +00:00
|
|
|
Filters.Add(new ActivatingFilter<Blog>(BlogDriver.ContentType.Name));
|
|
|
|
Filters.Add(new ActivatingFilter<CommonAspect>(BlogDriver.ContentType.Name));
|
|
|
|
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogDriver.ContentType.Name));
|
2009-11-21 09:47:18 +00:00
|
|
|
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
2010-01-15 23:44:22 +00:00
|
|
|
|
|
|
|
OnCreating<Blog>((context, blog) => {
|
|
|
|
string slug = !string.IsNullOrEmpty(blog.Slug)
|
|
|
|
? blog.Slug
|
|
|
|
: routableService.Slugify(blog.Name);
|
|
|
|
|
|
|
|
blog.Slug = routableService.GenerateUniqueSlug(slug,
|
|
|
|
blogService.Get().Where(
|
|
|
|
b => b.Slug.StartsWith(slug)).Select(
|
|
|
|
b => b.Slug));
|
|
|
|
});
|
2009-11-20 23:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-15 23:44:22 +00:00
|
|
|
}
|