mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Hooking up create blog to the new templating model (currently broken).
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043560
This commit is contained in:
@@ -34,11 +34,12 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
|
|
||||||
OnActivated<CommonAspect>(PropertySetHandlers);
|
|
||||||
OnCreating<CommonAspect>(DefaultTimestampsAndOwner);
|
|
||||||
OnLoaded<CommonAspect>(LazyLoadHandlers);
|
|
||||||
Filters.Add(new StorageFilter<CommonRecord>(repository));
|
Filters.Add(new StorageFilter<CommonRecord>(repository));
|
||||||
|
|
||||||
|
OnActivated<CommonAspect>(PropertySetHandlers);
|
||||||
|
OnActivated<CommonAspect>(DefaultTimestampsAndOwner);
|
||||||
|
OnLoaded<CommonAspect>(LazyLoadHandlers);
|
||||||
|
|
||||||
//OnGetDisplayViewModel<CommonAspect>();
|
//OnGetDisplayViewModel<CommonAspect>();
|
||||||
OnGetEditorViewModel<CommonAspect>(GetEditor);
|
OnGetEditorViewModel<CommonAspect>(GetEditor);
|
||||||
OnUpdateEditorViewModel<CommonAspect>(UpdateEditor);
|
OnUpdateEditorViewModel<CommonAspect>(UpdateEditor);
|
||||||
@@ -46,7 +47,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
void DefaultTimestampsAndOwner(CreateContentContext context, CommonAspect instance) {
|
void DefaultTimestampsAndOwner(ActivatedContentContext context, CommonAspect instance) {
|
||||||
// assign default create/modified dates
|
// assign default create/modified dates
|
||||||
if (instance.Record.CreatedUtc == null) {
|
if (instance.Record.CreatedUtc == null) {
|
||||||
instance.Record.CreatedUtc = _clock.UtcNow;
|
instance.Record.CreatedUtc = _clock.UtcNow;
|
||||||
|
@@ -81,24 +81,36 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Create() {
|
public ActionResult Create() {
|
||||||
return View(new CreateBlogViewModel());
|
//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 = _contentManager.New<Blog>("blog");
|
||||||
|
CreateBlogViewModel viewModel = new CreateBlogViewModel {
|
||||||
|
Blog = _contentManager.GetEditorViewModel(blog, null)
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Create(CreateBlogViewModel model) {
|
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")))
|
if (!_authorizer.Authorize(Permissions.CreateBlog, T("Couldn't create blog")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
model.Blog = _contentManager.UpdateEditorViewModel(_contentManager.New<Blog>("blog"), null, this);
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return View(model);
|
return View(model);
|
||||||
|
|
||||||
Blog blog = _blogService.Create(model.ToCreateBlogParams());
|
_contentManager.Create(model.Blog.Item.ContentItem);
|
||||||
|
|
||||||
//TEMP: (erikpo) ensure information has committed for this record
|
//TEMP: (erikpo) ensure information has committed for this record
|
||||||
var session = _sessionLocator.For(typeof(BlogRecord));
|
var session = _sessionLocator.For(typeof(BlogRecord));
|
||||||
session.Flush();
|
session.Flush();
|
||||||
|
|
||||||
return Redirect(Url.BlogForAdmin(blog.Slug));
|
return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Edit(string blogSlug) {
|
public ActionResult Edit(string blogSlug) {
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
using Orchard.Blogs.Services;
|
|
||||||
using Orchard.Blogs.ViewModels;
|
|
||||||
|
|
||||||
namespace Orchard.Blogs.Extensions {
|
|
||||||
public static class BlogCreateViewModelExtensions {
|
|
||||||
public static CreateBlogParams ToCreateBlogParams(this CreateBlogViewModel viewModel) {
|
|
||||||
return new CreateBlogParams() {Name = viewModel.Name, Description = viewModel.Description, Slug = viewModel.Slug/*, Enabled = viewModel.Enabled*/};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,6 +3,7 @@ using Orchard.Core.Common.Models;
|
|||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
using Orchard.Models.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogProvider : ContentHandler {
|
public class BlogProvider : ContentHandler {
|
||||||
@@ -16,6 +17,15 @@ namespace Orchard.Blogs.Models {
|
|||||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
||||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||||
Filters.Add(new ContentItemTemplates<Blog>("Blog", "Detail", "DetailAdmin", "Summary", "SummaryAdmin"));
|
Filters.Add(new ContentItemTemplates<Blog>("Blog", "Detail", "DetailAdmin", "Summary", "SummaryAdmin"));
|
||||||
|
|
||||||
|
OnGetEditorViewModel<Blog>((context, blog) =>
|
||||||
|
context.AddEditor(new TemplateViewModel(blog) {TemplateName = "BlogFields"})
|
||||||
|
);
|
||||||
|
|
||||||
|
OnUpdateEditorViewModel<Blog>((context, blog) => {
|
||||||
|
context.AddEditor(new TemplateViewModel(blog) {TemplateName = "BlogFields"});
|
||||||
|
context.Updater.TryUpdateModel(blog, "", null, null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -67,7 +67,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
<Compile Include="Controllers\BlogPostController.cs" />
|
<Compile Include="Controllers\BlogPostController.cs" />
|
||||||
<Compile Include="Extensions\BlogCreateViewModelExtensions.cs" />
|
|
||||||
<Compile Include="Extensions\BlogPostCreateViewModelExtensions.cs" />
|
<Compile Include="Extensions\BlogPostCreateViewModelExtensions.cs" />
|
||||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||||
<Compile Include="Extensions\UriExtensions.cs" />
|
<Compile Include="Extensions\UriExtensions.cs" />
|
||||||
@@ -120,10 +119,11 @@
|
|||||||
<Content Include="Views\Blog\Edit.aspx" />
|
<Content Include="Views\Blog\Edit.aspx" />
|
||||||
<Content Include="Views\Blog\EditorTemplates\BlogEditViewModel.ascx" />
|
<Content Include="Views\Blog\EditorTemplates\BlogEditViewModel.ascx" />
|
||||||
<Content Include="Views\Blog\EditorTemplates\BlogPermalink.ascx" />
|
<Content Include="Views\Blog\EditorTemplates\BlogPermalink.ascx" />
|
||||||
<Content Include="Views\Blog\EditorTemplates\CreateBlogViewModel.ascx" />
|
|
||||||
<Content Include="Views\Blog\Item.aspx" />
|
<Content Include="Views\Blog\Item.aspx" />
|
||||||
<Content Include="Views\Models\DisplayTemplates\BlogPostSummaryAdmin.ascx" />
|
<Content Include="Views\Models\DisplayTemplates\BlogPostSummaryAdmin.ascx" />
|
||||||
<Content Include="Views\Models\DisplayTemplates\BlogPostListAdmin.ascx" />
|
<Content Include="Views\Models\DisplayTemplates\BlogPostListAdmin.ascx" />
|
||||||
|
<Content Include="Views\Models\EditorTemplates\BlogFields.ascx" />
|
||||||
|
<Content Include="Views\Models\EditorTemplates\Blog.ascx" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@@ -30,14 +30,6 @@ namespace Orchard.Blogs.Services {
|
|||||||
return records.Select(rr => _contentManager.Get<Blog>(rr.Id));
|
return records.Select(rr => _contentManager.Get<Blog>(rr.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blog Create(CreateBlogParams parameters) {
|
|
||||||
return _contentManager.Create<Blog>("blog", init => {
|
|
||||||
init.Record.Description = parameters.Description;
|
|
||||||
init.As<RoutableAspect>().Record.Title = parameters.Name;
|
|
||||||
init.As<RoutableAspect>().Record.Slug = parameters.Slug;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Delete(Blog blog) {
|
public void Delete(Blog blog) {
|
||||||
_blogRepository.Delete(blog.Record);
|
_blogRepository.Delete(blog.Record);
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ namespace Orchard.Blogs.Services {
|
|||||||
public interface IBlogService : IDependency {
|
public interface IBlogService : IDependency {
|
||||||
Blog Get(string slug);
|
Blog Get(string slug);
|
||||||
IEnumerable<Blog> Get();
|
IEnumerable<Blog> Get();
|
||||||
Blog Create(CreateBlogParams parameters);
|
|
||||||
void Delete(Blog blog);
|
void Delete(Blog blog);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,16 +1,20 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.Models.ViewModels;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Blogs.ViewModels {
|
namespace Orchard.Blogs.ViewModels {
|
||||||
public class CreateBlogViewModel : AdminViewModel {
|
public class CreateBlogViewModel : AdminViewModel {
|
||||||
[Required]
|
public ItemEditorViewModel<Blog> Blog { get; set; }
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
//TODO: (erikpo) Need a data type for slug
|
//[Required]
|
||||||
[Required]
|
//public string Name { get; set; }
|
||||||
public string Slug { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
////TODO: (erikpo) Need a data type for slug
|
||||||
|
//[Required]
|
||||||
|
//public string Slug { get; set; }
|
||||||
|
|
||||||
|
//public string Description { get; set; }
|
||||||
|
|
||||||
//[Required]
|
//[Required]
|
||||||
//public bool Enabled { get; set; }
|
//public bool Enabled { get; set; }
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Blogs.ViewModels.CreateBlogViewModel>" ValidateRequest="false" %>
|
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<CreateBlogViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||||
<%@ Import Namespace="Orchard.Security" %>
|
<%@ Import Namespace="Orchard.Security" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||||
@@ -6,7 +8,7 @@
|
|||||||
<h2>Add Blog</h2>
|
<h2>Add Blog</h2>
|
||||||
<% using (Html.BeginForm()) { %>
|
<% using (Html.BeginForm()) { %>
|
||||||
<%=Html.ValidationSummary() %>
|
<%=Html.ValidationSummary() %>
|
||||||
<%=Html.EditorForModel() %>
|
<%=Html.EditorForItem(vm => vm.Blog) %>
|
||||||
<fieldset><input class="button" type="submit" value="Create" /></fieldset>
|
<fieldset><input class="button" type="submit" value="Create" /></fieldset>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% Html.Include("AdminFoot"); %>
|
<% Html.Include("AdminFoot"); %>
|
@@ -0,0 +1,5 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<Blog>>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Models.ViewModels"%>
|
||||||
|
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
|
<%=Html.EditorZonesAny() %>
|
@@ -1,5 +1,5 @@
|
|||||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CreateBlogViewModel>" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Blog>" %>
|
||||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
<%@ Import Namespace="Orchard.Blogs.Models" %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="Name">Blog Name</label>
|
<label for="Name">Blog Name</label>
|
||||||
<%=Html.EditorFor(m => m.Name) %>
|
<%=Html.EditorFor(m => m.Name) %>
|
Reference in New Issue
Block a user