diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogAdminController.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogAdminController.cs index a560d3bbd..fe6d0a4af 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogAdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogAdminController.cs @@ -1,19 +1,130 @@ using System.Linq; using System.Web.Mvc; +using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; using Orchard.Blogs.Services; using Orchard.Blogs.ViewModels; +using Orchard.ContentManagement; +using Orchard.Data; +using Orchard.Localization; using Orchard.Mvc.Results; +using Orchard.Security; +using Orchard.UI.Notify; namespace Orchard.Blogs.Controllers { [ValidateInput(false)] - public class BlogAdminController : Controller { + public class BlogAdminController : Controller, IUpdateModel { private readonly IOrchardServices _services; private readonly IBlogService _blogService; + private readonly ISessionLocator _sessionLocator; + private readonly IAuthorizer _authorizer; + private readonly INotifier _notifier; - public BlogAdminController(IOrchardServices services, IBlogService blogService) { + public BlogAdminController(IOrchardServices services, IBlogService blogService, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier) { _services = services; _blogService = blogService; + _sessionLocator = sessionLocator; + _authorizer = authorizer; + _notifier = notifier; + T = NullLocalizer.Instance; + } + + private Localizer T { get; set; } + + public ActionResult Create() { + //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute + if (!_authorizer.Authorize(Permissions.CreateBlog, T("Not allowed to create blogs"))) + return new HttpUnauthorizedResult(); + + Blog blog = _services.ContentManager.New("blog"); + + if (blog == null) + return new NotFoundResult(); + + var model = new CreateBlogViewModel { + Blog = _services.ContentManager.BuildEditorModel(blog) + }; + + return View(model); + } + + [HttpPost] + public ActionResult Create(CreateBlogViewModel model) { + //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute + if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog"))) + return new HttpUnauthorizedResult(); + + model.Blog = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New("blog"), this); + + if (!ModelState.IsValid) + return View(model); + + _services.ContentManager.Create(model.Blog.Item.ContentItem); + + //TEMP: (erikpo) ensure information has committed for this record + var session = _sessionLocator.For(typeof(BlogRecord)); + session.Flush(); + + return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug)); + } + + public ActionResult Edit(string blogSlug) { + //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute + if (!_authorizer.Authorize(Permissions.ModifyBlog, T("Not allowed to edit blog"))) + return new HttpUnauthorizedResult(); + + //TODO: (erikpo) Move looking up the current blog up into a modelbinder + Blog blog = _blogService.Get(blogSlug); + + if (blog == null) + return new NotFoundResult(); + + var model = new BlogEditViewModel { + Blog = _services.ContentManager.BuildEditorModel(blog) + }; + + return View(model); + } + + [HttpPost] + public ActionResult Edit(string blogSlug, FormCollection input) { + if (!_authorizer.Authorize(Permissions.ModifyBlog, T("Couldn't edit blog"))) + return new HttpUnauthorizedResult(); + + //TODO: (erikpo) Move looking up the current blog up into a modelbinder + Blog blog = _blogService.Get(blogSlug); + + if (blog == null) + return new NotFoundResult(); + + var model = new BlogEditViewModel { + Blog = _services.ContentManager.UpdateEditorModel(blog, this) + }; + + if (!ModelState.IsValid) + return View(model); + + _notifier.Information(T("Blog information updated")); + + return Redirect(Url.BlogsForAdmin()); + } + + //[HttpPost] <- todo: (heskew) make all add/edit/remove POST only and verify the AntiForgeryToken + public ActionResult Delete(string blogSlug) { + if (!_authorizer.Authorize(Permissions.DeleteBlog, T("Couldn't delete blog"))) + return new HttpUnauthorizedResult(); + + //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.BlogsForAdmin()); } public ActionResult List() { @@ -39,5 +150,13 @@ namespace Orchard.Blogs.Controllers { return View(model); } + + bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { + return TryUpdateModel(model, prefix, includeProperties, excludeProperties); + } + + void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) { + ModelState.AddModelError(key, errorMessage.ToString()); + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogController.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogController.cs index 3d3576d63..396c2eaf7 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogController.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogController.cs @@ -1,36 +1,24 @@ using System.Linq; using System.Web.Mvc; -using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; using Orchard.Blogs.Services; using Orchard.Blogs.ViewModels; using Orchard.Data; -using Orchard.Localization; -using Orchard.ContentManagement; using Orchard.Mvc.Results; using Orchard.Security; using Orchard.UI.Notify; namespace Orchard.Blogs.Controllers { [ValidateInput(false)] - public class BlogController : Controller, IUpdateModel { + public class BlogController : Controller { private readonly IOrchardServices _services; - private readonly ISessionLocator _sessionLocator; - private readonly IAuthorizer _authorizer; - private readonly INotifier _notifier; private readonly IBlogService _blogService; public BlogController(IOrchardServices services, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier, IBlogService blogService) { _services = services; - _sessionLocator = sessionLocator; - _authorizer = authorizer; - _notifier = notifier; _blogService = blogService; - T = NullLocalizer.Instance; } - private Localizer T { get; set; } - public ActionResult List() { var model = new BlogsViewModel { Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary")) @@ -52,109 +40,5 @@ namespace Orchard.Blogs.Controllers { return View(model); } - - public ActionResult Create() { - //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute - if (!_authorizer.Authorize(Permissions.CreateBlog, T("Not allowed to create blogs"))) - return new HttpUnauthorizedResult(); - - Blog blog = _services.ContentManager.New("blog"); - - if (blog == null) - return new NotFoundResult(); - - var model = new CreateBlogViewModel { - Blog = _services.ContentManager.BuildEditorModel(blog) - }; - - return View(model); - } - - [HttpPost] - public ActionResult Create(CreateBlogViewModel model) { - //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute - if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog"))) - return new HttpUnauthorizedResult(); - - model.Blog = _services.ContentManager.UpdateEditorModel(_services.ContentManager.New("blog"), this); - - if (!ModelState.IsValid) - return View(model); - - _services.ContentManager.Create(model.Blog.Item.ContentItem); - - //TEMP: (erikpo) ensure information has committed for this record - var session = _sessionLocator.For(typeof(BlogRecord)); - session.Flush(); - - return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug)); - } - - public ActionResult Edit(string blogSlug) { - //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute - if (!_authorizer.Authorize(Permissions.ModifyBlog, T("Not allowed to edit blog"))) - return new HttpUnauthorizedResult(); - - //TODO: (erikpo) Move looking up the current blog up into a modelbinder - Blog blog = _blogService.Get(blogSlug); - - if (blog == null) - return new NotFoundResult(); - - var model = new BlogEditViewModel { - Blog = _services.ContentManager.BuildEditorModel(blog) - }; - - return View(model); - } - - [HttpPost] - public ActionResult Edit(string blogSlug, FormCollection input) { - if (!_authorizer.Authorize(Permissions.ModifyBlog, T("Couldn't edit blog"))) - return new HttpUnauthorizedResult(); - - //TODO: (erikpo) Move looking up the current blog up into a modelbinder - Blog blog = _blogService.Get(blogSlug); - - if (blog == null) - return new NotFoundResult(); - - var model = new BlogEditViewModel { - Blog = _services.ContentManager.UpdateEditorModel(blog, this) - }; - - if (!ModelState.IsValid) - return View(model); - - _notifier.Information(T("Blog information updated")); - - return Redirect(Url.BlogsForAdmin()); - } - - //[HttpPost] <- todo: (heskew) make all add/edit/remove POST only and verify the AntiForgeryToken - public ActionResult Delete(string blogSlug) { - if (!_authorizer.Authorize(Permissions.DeleteBlog, T("Couldn't delete blog"))) - return new HttpUnauthorizedResult(); - - //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.BlogsForAdmin()); - } - - bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { - return TryUpdateModel(model, prefix, includeProperties, excludeProperties); - } - void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) { - ModelState.AddModelError(key, errorMessage.ToString()); - } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostAdminController.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostAdminController.cs new file mode 100644 index 000000000..f15dce317 --- /dev/null +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostAdminController.cs @@ -0,0 +1,179 @@ +using System.Web.Mvc; +using Orchard.Blogs.Extensions; +using Orchard.Blogs.Models; +using Orchard.Blogs.Services; +using Orchard.Blogs.ViewModels; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Records; +using Orchard.Data; +using Orchard.Localization; +using Orchard.Mvc.Results; +using Orchard.UI.Notify; + +namespace Orchard.Blogs.Controllers { + public class BlogPostAdminController : Controller, IUpdateModel { + private readonly IOrchardServices _services; + private readonly IBlogService _blogService; + private readonly IBlogPostService _blogPostService; + private readonly ISessionLocator _sessionLocator; + + public BlogPostAdminController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, ISessionLocator sessionLocator) { + _services = services; + _blogService = blogService; + _blogPostService = blogPostService; + _sessionLocator = sessionLocator; + T = NullLocalizer.Instance; + } + + private Localizer T { get; set; } + + public ActionResult Create(string blogSlug) { + //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute + if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post"))) + return new HttpUnauthorizedResult(); + + //TODO: (erikpo) Move looking up the current blog up into a modelbinder + Blog blog = _blogService.Get(blogSlug); + + if (blog == null) + return new NotFoundResult(); + + var blogPost = _services.ContentManager.BuildEditorModel(_services.ContentManager.New("blogpost")); + blogPost.Item.Blog = blog; + + var model = new CreateBlogPostViewModel { + BlogPost = blogPost + }; + + return View(model); + } + + [HttpPost] + public ActionResult Create(string blogSlug, CreateBlogPostViewModel model) { + if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Couldn't create blog post"))) + return new HttpUnauthorizedResult(); + + //TODO: (erikpo) Move looking up the current blog up into a modelbinder + Blog blog = _blogService.Get(blogSlug); + + if (blog == null) + return new NotFoundResult(); + + bool publishNow = false; + if (string.Equals(Request.Form["Command"], "PublishNow")) { + publishNow = true; + } + + BlogPost blogPost = _services.ContentManager.Create("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; }); + model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this); + + if (!ModelState.IsValid) { + _services.TransactionManager.Cancel(); + + return View(model); + } + + //TEMP: (erikpo) ensure information has committed for this record + var session = _sessionLocator.For(typeof(ContentItemRecord)); + session.Flush(); + + return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug)); + } + + public ActionResult Edit(string blogSlug, string postSlug) { + if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post"))) + return new HttpUnauthorizedResult(); + + //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, VersionOptions.Latest); + + if (post == null) + return new NotFoundResult(); + + var model = new BlogPostEditViewModel { + BlogPost = _services.ContentManager.BuildEditorModel(post) + }; + + return View(model); + } + + [HttpPost, ActionName("Edit")] + public ActionResult EditPOST(string blogSlug, string postSlug) { + if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post"))) + return new HttpUnauthorizedResult(); + + //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, VersionOptions.Latest); + + if (post == null) + return new NotFoundResult(); + + bool publishNow = false; + if (string.Equals(Request.Form["Command"], "PublishNow")) { + publishNow = true; + } + + if (publishNow) + _blogPostService.Publish(post); + else + _blogPostService.Unpublish(post); + + var model = new BlogPostEditViewModel { + BlogPost = _services.ContentManager.UpdateEditorModel(post, this) + }; + + TryUpdateModel(model); + + if (!ModelState.IsValid) { + _services.TransactionManager.Cancel(); + + return View(model); + } + + _services.Notifier.Information(T("Blog post information updated.")); + + return Redirect(Url.BlogPostEdit(blog.Slug, post.Slug)); + } + + [HttpPost] + public ActionResult Delete(string blogSlug, string postSlug) { + if (!_services.Authorizer.Authorize(Permissions.DeletePost, T("Couldn't delete blog post"))) + return new HttpUnauthorizedResult(); + + //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); + + _services.Notifier.Information(T("Blog post was successfully deleted")); + + return Redirect(Url.BlogForAdmin(blogSlug)); + } + + bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { + return TryUpdateModel(model, prefix, includeProperties, excludeProperties); + } + + void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) { + ModelState.AddModelError(key, errorMessage.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostController.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostController.cs index 914dc55ab..ab72d3f04 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostController.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Controllers/BlogPostController.cs @@ -1,32 +1,22 @@ using System.Linq; using System.Text.RegularExpressions; using System.Web.Mvc; -using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; using Orchard.Blogs.Services; using Orchard.Blogs.ViewModels; -using Orchard.ContentManagement.Records; -using Orchard.Data; using Orchard.Localization; using Orchard.ContentManagement; using Orchard.Mvc.Results; -using Orchard.UI.Notify; namespace Orchard.Blogs.Controllers { [ValidateInput(false)] - public class BlogPostController : Controller, IUpdateModel { + public class BlogPostController : Controller { private readonly IOrchardServices _services; - private readonly ISessionLocator _sessionLocator; private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; - public BlogPostController( - IOrchardServices services, - ISessionLocator sessionLocator, - IBlogService blogService, - IBlogPostService blogPostService) { + public BlogPostController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService) { _services = services; - _sessionLocator = sessionLocator; _blogService = blogService; _blogPostService = blogPostService; T = NullLocalizer.Instance; @@ -77,6 +67,7 @@ namespace Orchard.Blogs.Controllers { return View(model); } + //TODO: (erikpo) This should move to be part of the RoutableAspect public ActionResult Slugify(string value) { string slug = value; @@ -99,153 +90,5 @@ namespace Orchard.Blogs.Controllers { return Json(slug); } - - public ActionResult Create(string blogSlug) { - //TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute - if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post"))) - return new HttpUnauthorizedResult(); - - //TODO: (erikpo) Move looking up the current blog up into a modelbinder - Blog blog = _blogService.Get(blogSlug); - - if (blog == null) - return new NotFoundResult(); - - var blogPost = _services.ContentManager.BuildEditorModel(_services.ContentManager.New("blogpost")); - blogPost.Item.Blog = blog; - - var model = new CreateBlogPostViewModel { - BlogPost = blogPost - }; - - return View(model); - } - - [HttpPost] - public ActionResult Create(string blogSlug, CreateBlogPostViewModel model) { - if (!_services.Authorizer.Authorize(Permissions.CreatePost, T("Couldn't create blog post"))) - return new HttpUnauthorizedResult(); - - //TODO: (erikpo) Move looking up the current blog up into a modelbinder - Blog blog = _blogService.Get(blogSlug); - - if (blog == null) - return new NotFoundResult(); - - bool publishNow = false; - if (string.Equals(Request.Form["Command"], "PublishNow")) { - publishNow = true; - } - - BlogPost blogPost = _services.ContentManager.Create("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; }); - model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this); - - if (!ModelState.IsValid) { - _services.TransactionManager.Cancel(); - - return View(model); - } - - //TEMP: (erikpo) ensure information has committed for this record - var session = _sessionLocator.For(typeof(ContentItemRecord)); - session.Flush(); - - return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug)); - } - - public ActionResult Edit(string blogSlug, string postSlug) { - if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post"))) - return new HttpUnauthorizedResult(); - - //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, VersionOptions.Latest); - - if (post == null) - return new NotFoundResult(); - - var model = new BlogPostEditViewModel { - BlogPost = _services.ContentManager.BuildEditorModel(post) - }; - - return View(model); - } - - [HttpPost, ActionName("Edit")] - public ActionResult EditPOST(string blogSlug, string postSlug) { - if (!_services.Authorizer.Authorize(Permissions.ModifyPost, T("Couldn't edit blog post"))) - return new HttpUnauthorizedResult(); - - //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, VersionOptions.Latest); - - if (post == null) - return new NotFoundResult(); - - bool publishNow = false; - if (string.Equals(Request.Form["Command"], "PublishNow")) { - publishNow = true; - } - - if (publishNow) - _blogPostService.Publish(post); - else - _blogPostService.Unpublish(post); - - var model = new BlogPostEditViewModel { - BlogPost = _services.ContentManager.UpdateEditorModel(post, this) - }; - - TryUpdateModel(model); - - if (!ModelState.IsValid) { - _services.TransactionManager.Cancel(); - - return View(model); - } - - _services.Notifier.Information(T("Blog post information updated.")); - - return Redirect(Url.BlogPostEdit(blog.Slug, post.Slug)); - } - - [HttpPost] - public ActionResult Delete(string blogSlug, string postSlug) { - if (!_services.Authorizer.Authorize(Permissions.DeletePost, T("Couldn't delete blog post"))) - return new HttpUnauthorizedResult(); - - //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); - - _services.Notifier.Information(T("Blog post was successfully deleted")); - - return Redirect(Url.BlogForAdmin(blogSlug)); - } - - bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { - return TryUpdateModel(model, prefix, includeProperties, excludeProperties); - } - void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) { - ModelState.AddModelError(key, errorMessage.ToString()); - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Extensions/UrlHelperExtensions.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Extensions/UrlHelperExtensions.cs index 9b9589a57..7b56d3c9d 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Extensions/UrlHelperExtensions.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Extensions/UrlHelperExtensions.cs @@ -31,15 +31,15 @@ namespace Orchard.Blogs.Extensions { } public static string BlogCreate(this UrlHelper urlHelper) { - return urlHelper.Action("Create", "Blog", new {area = "Orchard.Blogs"}); + return urlHelper.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}); } public static string BlogEdit(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Edit", "Blog", new {blogSlug, area = "Orchard.Blogs"}); + return urlHelper.Action("Edit", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); } public static string BlogDelete(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Delete", "Blog", new {blogSlug, area = "Orchard.Blogs"}); + return urlHelper.Action("Delete", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); } public static string BlogPost(this UrlHelper urlHelper, string blogSlug, string postSlug) { @@ -47,15 +47,15 @@ namespace Orchard.Blogs.Extensions { } public static string BlogPostCreate(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Create", "BlogPost", new {blogSlug, area = "Orchard.Blogs"}); + return urlHelper.Action("Create", "BlogPostAdmin", new {blogSlug, area = "Orchard.Blogs"}); } public static string BlogPostEdit(this UrlHelper urlHelper, string blogSlug, string postSlug) { - return urlHelper.Action("Edit", "BlogPost", new {blogSlug, postSlug, area = "Orchard.Blogs"}); + return urlHelper.Action("Edit", "BlogPostAdmin", 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"}); + return urlHelper.Action("Delete", "BlogPostAdmin", new {blogSlug, postSlug, area = "Orchard.Blogs"}); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Packages/Orchard.Blogs/Orchard.Blogs.csproj index a23902f2d..484addaf8 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Orchard.Blogs.csproj @@ -76,6 +76,7 @@ + @@ -110,8 +111,8 @@ - - + + @@ -125,8 +126,8 @@ - - + + diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Routes.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Routes.cs index 6d93563c1..9fdbf4147 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Routes.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Routes.cs @@ -40,7 +40,7 @@ namespace Orchard.Blogs { "Admin/Blogs/Create", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "Blog"}, + {"controller", "BlogAdmin"}, {"action", "Create"} }, new RouteValueDictionary(), @@ -54,7 +54,7 @@ namespace Orchard.Blogs { "Admin/Blogs/{blogSlug}/Edit", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "Blog"}, + {"controller", "BlogAdmin"}, {"action", "Edit"} }, new RouteValueDictionary { @@ -70,7 +70,7 @@ namespace Orchard.Blogs { "Admin/Blogs/{blogSlug}/Delete", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "Blog"}, + {"controller", "BlogAdmin"}, {"action", "Delete"} }, new RouteValueDictionary { @@ -102,7 +102,7 @@ namespace Orchard.Blogs { "Admin/Blogs/{blogSlug}/Posts/Create", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, + {"controller", "BlogPostAdmin"}, {"action", "Create"} }, new RouteValueDictionary { @@ -118,7 +118,7 @@ namespace Orchard.Blogs { "Admin/Blogs/{blogSlug}/Posts/{postSlug}/Edit", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, + {"controller", "BlogPostAdmin"}, {"action", "Edit"} }, new RouteValueDictionary { @@ -134,7 +134,7 @@ namespace Orchard.Blogs { "Admin/Blogs/{blogSlug}/Posts/{postSlug}/Delete", new RouteValueDictionary { {"area", "Orchard.Blogs"}, - {"controller", "BlogPost"}, + {"controller", "BlogPostAdmin"}, {"action", "Delete"} }, new RouteValueDictionary { @@ -145,22 +145,6 @@ namespace Orchard.Blogs { }, new MvcRouteHandler()) }, - //new RouteDescriptor { - // Route = new Route( - // "Admin/Blogs/{blogSlug}/Posts", - // new RouteValueDictionary { - // {"area", "Orchard.Blogs"}, - // {"controller", "BlogPostAdmin"}, - // {"action", "List"} - // }, - // new RouteValueDictionary { - // {"blogSlug", new IsBlogConstraint(_blogService)} - // }, - // new RouteValueDictionary { - // {"area", "Orchard.Blogs"} - // }, - // new MvcRouteHandler()) - // }, new RouteDescriptor { Route = new Route( "Admin/Blogs", diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Services/BlogService.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Services/BlogService.cs index e737306cf..5f7b66596 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Services/BlogService.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Services/BlogService.cs @@ -2,17 +2,14 @@ using System.Collections.Generic; using System.Linq; using Orchard.Blogs.Models; using Orchard.Core.Common.Records; -using Orchard.Data; using Orchard.ContentManagement; namespace Orchard.Blogs.Services { public class BlogService : IBlogService { private readonly IContentManager _contentManager; - private readonly IRepository _blogRepository; - public BlogService(IContentManager contentManager, IRepository blogRepository) { + public BlogService(IContentManager contentManager) { _contentManager = contentManager; - _blogRepository = blogRepository; } public Blog Get(string slug) { @@ -29,7 +26,7 @@ namespace Orchard.Blogs.Services { } public void Delete(Blog blog) { - _blogRepository.Delete(blog.Record); + _contentManager.Remove(blog.ContentItem); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Create.ascx b/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogAdmin/Create.ascx similarity index 100% rename from src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Create.ascx rename to src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogAdmin/Create.ascx diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Edit.ascx b/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogAdmin/Edit.ascx similarity index 100% rename from src/Orchard.Web/Packages/Orchard.Blogs/Views/Blog/Edit.ascx rename to src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogAdmin/Edit.ascx diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPost/Create.ascx b/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPostAdmin/Create.ascx similarity index 100% rename from src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPost/Create.ascx rename to src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPostAdmin/Create.ascx diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPost/Edit.ascx b/src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPostAdmin/Edit.ascx similarity index 100% rename from src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPost/Edit.ascx rename to src/Orchard.Web/Packages/Orchard.Blogs/Views/BlogPostAdmin/Edit.ascx