- Pages: minor refactoring in the controllers to use the IOrchardServices property injection instead of injecting the individual core services in the constructor.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045093
This commit is contained in:
suhacan
2010-01-07 03:04:04 +00:00
parent 4bdd7de389
commit 748f52ec46
2 changed files with 15 additions and 34 deletions

View File

@@ -14,24 +14,16 @@ namespace Orchard.Pages.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
public class AdminController : Controller, IUpdateModel { public class AdminController : Controller, IUpdateModel {
private readonly ISessionLocator _sessionLocator; private readonly ISessionLocator _sessionLocator;
private readonly IContentManager _contentManager;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
private readonly IPageService _pageService; private readonly IPageService _pageService;
private readonly ISlugConstraint _slugConstraint; private readonly ISlugConstraint _slugConstraint;
public AdminController( public AdminController(
IOrchardServices services, IOrchardServices services,
ISessionLocator sessionLocator, IContentManager contentManager, ISessionLocator sessionLocator,
IAuthorizer authorizer,
INotifier notifier,
IPageService pageService, IPageService pageService,
ISlugConstraint slugConstraint) { ISlugConstraint slugConstraint) {
Services = services; Services = services;
_sessionLocator = sessionLocator; _sessionLocator = sessionLocator;
_contentManager = contentManager;
_authorizer = authorizer;
_notifier = notifier;
_pageService = pageService; _pageService = pageService;
_slugConstraint = slugConstraint; _slugConstraint = slugConstraint;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
@@ -50,10 +42,10 @@ namespace Orchard.Pages.Controllers {
} }
public ActionResult Create() { public ActionResult Create() {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page"))) if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var page = _contentManager.BuildEditorModel(_contentManager.New<Page>("page")); var page = Services.ContentManager.BuildEditorModel(Services.ContentManager.New<Page>("page"));
var model = new PageCreateViewModel { var model = new PageCreateViewModel {
Page = page Page = page
@@ -64,11 +56,11 @@ namespace Orchard.Pages.Controllers {
[HttpPost, ActionName("Create")] [HttpPost, ActionName("Create")]
public ActionResult CreatePOST(PageCreateViewModel model) { public ActionResult CreatePOST(PageCreateViewModel model) {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page"))) if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
Page page = _contentManager.Create<Page>("page"); Page page = Services.ContentManager.Create<Page>("page");
model.Page = _contentManager.UpdateEditorModel(page, this); model.Page = Services.ContentManager.UpdateEditorModel(page, this);
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(model); return View(model);
@@ -80,7 +72,7 @@ namespace Orchard.Pages.Controllers {
} }
public ActionResult Edit(string pageSlug) { public ActionResult Edit(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page"))) if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug); Page page = _pageService.Get(pageSlug);
@@ -89,7 +81,7 @@ namespace Orchard.Pages.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new PageEditViewModel { var model = new PageEditViewModel {
Page = _contentManager.BuildEditorModel(page) Page = Services.ContentManager.BuildEditorModel(page)
}; };
return View(model); return View(model);
@@ -97,7 +89,7 @@ namespace Orchard.Pages.Controllers {
[HttpPost, ActionName("Edit")] [HttpPost, ActionName("Edit")]
public ActionResult EditPOST(string pageSlug) { public ActionResult EditPOST(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page"))) if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug); Page page = _pageService.Get(pageSlug);
@@ -106,7 +98,7 @@ namespace Orchard.Pages.Controllers {
return new NotFoundResult(); return new NotFoundResult();
var model = new PageEditViewModel { var model = new PageEditViewModel {
Page = _contentManager.UpdateEditorModel(page, this) Page = Services.ContentManager.UpdateEditorModel(page, this)
}; };
TryUpdateModel(model); TryUpdateModel(model);
@@ -116,13 +108,13 @@ namespace Orchard.Pages.Controllers {
return View(model); return View(model);
} }
_notifier.Information(T("Page information updated.")); Services.Notifier.Information(T("Page information updated."));
return RedirectToAction("Edit", new { pageSlug = page.Slug }); return RedirectToAction("Edit", new { pageSlug = page.Slug });
} }
[HttpPost] [HttpPost]
public ActionResult Delete(string pageSlug) { public ActionResult Delete(string pageSlug) {
if (!_authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page"))) if (!Services.Authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug); Page page = _pageService.Get(pageSlug);
@@ -132,7 +124,7 @@ namespace Orchard.Pages.Controllers {
_pageService.Delete(page); _pageService.Delete(page);
_notifier.Information(T("Page was successfully deleted")); Services.Notifier.Information(T("Page was successfully deleted"));
return RedirectToAction("List"); return RedirectToAction("List");
} }

View File

@@ -4,29 +4,18 @@ using Orchard.Localization;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Pages.Services; using Orchard.Pages.Services;
using Orchard.Pages.ViewModels; using Orchard.Pages.ViewModels;
using Orchard.Security;
using Orchard.UI.Notify;
namespace Orchard.Pages.Controllers { namespace Orchard.Pages.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
public class PageController : Controller, IUpdateModel { public class PageController : Controller, IUpdateModel {
private readonly IContentManager _contentManager;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
private readonly IPageService _pageService; private readonly IPageService _pageService;
private readonly ISlugConstraint _slugConstraint; private readonly ISlugConstraint _slugConstraint;
public PageController( public PageController(
IOrchardServices services, IOrchardServices services,
IContentManager contentManager,
IAuthorizer authorizer,
INotifier notifier,
IPageService pageService, IPageService pageService,
ISlugConstraint slugConstraint) { ISlugConstraint slugConstraint) {
Services = services; Services = services;
_contentManager = contentManager;
_authorizer = authorizer;
_notifier = notifier;
_pageService = pageService; _pageService = pageService;
_slugConstraint = slugConstraint; _slugConstraint = slugConstraint;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
@@ -36,7 +25,7 @@ namespace Orchard.Pages.Controllers {
private Localizer T { get; set; } private Localizer T { get; set; }
public ActionResult Item(string slug) { public ActionResult Item(string slug) {
if (!_authorizer.Authorize(Permissions.ViewPages, T("Couldn't view page"))) if (!Services.Authorizer.Authorize(Permissions.ViewPages, T("Couldn't view page")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
if (slug == null) { if (slug == null) {
@@ -48,7 +37,7 @@ namespace Orchard.Pages.Controllers {
var page = _pageService.Get(slug); var page = _pageService.Get(slug);
var model = new PageViewModel { var model = new PageViewModel {
Page = _contentManager.BuildDisplayModel(page, "Detail") Page = Services.ContentManager.BuildDisplayModel(page, "Detail")
}; };
return View(model); return View(model);
} }