Added all the infrastructure for deleting Blogs and BlogPosts.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043102
This commit is contained in:
ErikPorter
2009-12-03 19:50:57 +00:00
parent 9136b28f5d
commit a13df76497
9 changed files with 93 additions and 2 deletions

View File

@@ -116,6 +116,21 @@ namespace Orchard.Blogs.Controllers {
return Redirect(Url.BlogsForAdmin());
}
[HttpPost]
public ActionResult Delete(string blogSlug) {
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
Blog blog = _blogService.Get(blogSlug);
if (blog == null)
return new NotFoundResult();
_blogService.Delete(blog);
_notifier.Information(T("Blog was successfully deleted"));
return Redirect(Url.Blogs());
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -145,6 +145,26 @@ namespace Orchard.Blogs.Controllers {
return Redirect(Url.BlogPostEdit(blog.Slug, values.GetValue(ControllerContext, "Slug").AttemptedValue));
}
[HttpPost]
public ActionResult Delete(string blogSlug, string postSlug) {
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
Blog blog = _blogService.Get(blogSlug);
if (blog == null)
return new NotFoundResult();
BlogPost post = _blogPostService.Get(blog, postSlug);
if (post == null)
return new NotFoundResult();
_blogPostService.Delete(post);
_notifier.Information(T("Blog post was successfully deleted"));
return Redirect(Url.BlogForAdmin(blogSlug));
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -26,6 +26,10 @@ namespace Orchard.Blogs.Extensions {
return urlHelper.Action("Edit", "Blog", new {blogSlug, area = "Orchard.Blogs"});
}
public static string BlogDelete(this UrlHelper urlHelper, string blogSlug) {
return urlHelper.Action("Delete", "Blog", new {blogSlug, area = "Orchard.Blogs"});
}
public static string BlogPost(this UrlHelper urlHelper, string blogSlug, string postSlug) {
return urlHelper.Action("Item", "BlogPost", new {blogSlug, postSlug, area = "Orchard.Blogs"});
}
@@ -37,5 +41,9 @@ namespace Orchard.Blogs.Extensions {
public static string BlogPostEdit(this UrlHelper urlHelper, string blogSlug, string postSlug) {
return urlHelper.Action("Edit", "BlogPost", new {blogSlug, postSlug, area = "Orchard.Blogs"});
}
public static string BlogPostDelete(this UrlHelper urlHelper, string blogSlug, string postSlug) {
return urlHelper.Action("Delete", "BlogPost", new {blogSlug, postSlug, area = "Orchard.Blogs"});
}
}
}

View File

@@ -1,8 +1,10 @@
using System.Collections.Generic;
using Orchard.Data.Conventions;
using Orchard.Models.Records;
namespace Orchard.Blogs.Models {
public class BlogRecord : ContentPartRecord {
[CascadeAllDeleteOrphan]
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
public virtual string Description { get; set; }
//public virtual bool Enabled { get; set; }

View File

@@ -51,6 +51,22 @@ namespace Orchard.Blogs {
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/{blogSlug}/Delete",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "Blog"},
{"action", "Delete"}
},
new RouteValueDictionary {
{"blogSlug", new IsBlogConstraint(_blogService)}
},
new RouteValueDictionary {
{"area", "Orchard.Blogs"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/{blogSlug}",
@@ -99,6 +115,22 @@ namespace Orchard.Blogs {
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/{blogSlug}/Posts/{postSlug}/Delete",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "Delete"}
},
new RouteValueDictionary {
{"blogSlug", new IsBlogConstraint(_blogService)}
},
new RouteValueDictionary {
{"area", "Orchard.Blogs"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/{blogSlug}/Posts",

View File

@@ -9,10 +9,12 @@ using Orchard.Models;
namespace Orchard.Blogs.Services {
public class BlogPostService : IBlogPostService {
private readonly IContentManager _contentManager;
private readonly IRepository<BlogPostRecord> _blogPostRepository;
private readonly IRepository<RoutableRecord> _routableRepository;
public BlogPostService(IContentManager contentManager, IRepository<RoutableRecord> routableRepository) {
public BlogPostService(IContentManager contentManager, IRepository<BlogPostRecord> blogPostRepository, IRepository<RoutableRecord> routableRepository) {
_contentManager = contentManager;
_blogPostRepository = blogPostRepository;
_routableRepository = routableRepository;
}
@@ -48,5 +50,9 @@ namespace Orchard.Blogs.Services {
bp.Record.Blog.PostCount++;
});
}
public void Delete(BlogPost blogPost) {
_blogPostRepository.Delete(blogPost.Record);
}
}
}

View File

@@ -9,10 +9,12 @@ using Orchard.Models;
namespace Orchard.Blogs.Services {
public class BlogService : IBlogService {
private readonly IContentManager _contentManager;
private readonly IRepository<BlogRecord> _blogRepository;
private readonly IRepository<RoutableRecord> _routableRepository;
public BlogService(IContentManager contentManager, IRepository<RoutableRecord> routableRepository) {
public BlogService(IContentManager contentManager, IRepository<BlogRecord> blogRepository, IRepository<RoutableRecord> routableRepository) {
_contentManager = contentManager;
_blogRepository = blogRepository;
_routableRepository = routableRepository;
}
@@ -35,5 +37,9 @@ namespace Orchard.Blogs.Services {
init.As<RoutableAspect>().Record.Slug = parameters.Slug;
});
}
public void Delete(Blog blog) {
_blogRepository.Delete(blog.Record);
}
}
}

View File

@@ -6,5 +6,6 @@ namespace Orchard.Blogs.Services {
BlogPost Get(Blog blog, string slug);
IEnumerable<BlogPost> Get(Blog blog);
BlogPost Create(CreateBlogPostParams parameters);
void Delete(BlogPost blogPost);
}
}

View File

@@ -6,5 +6,6 @@ namespace Orchard.Blogs.Services {
Blog Get(string slug);
IEnumerable<Blog> Get();
Blog Create(CreateBlogParams parameters);
void Delete(Blog blog);
}
}