mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +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;
|
||||
T = NullLocalizer.Instance;
|
||||
|
||||
OnActivated<CommonAspect>(PropertySetHandlers);
|
||||
OnCreating<CommonAspect>(DefaultTimestampsAndOwner);
|
||||
OnLoaded<CommonAspect>(LazyLoadHandlers);
|
||||
Filters.Add(new StorageFilter<CommonRecord>(repository));
|
||||
|
||||
OnActivated<CommonAspect>(PropertySetHandlers);
|
||||
OnActivated<CommonAspect>(DefaultTimestampsAndOwner);
|
||||
OnLoaded<CommonAspect>(LazyLoadHandlers);
|
||||
|
||||
//OnGetDisplayViewModel<CommonAspect>();
|
||||
OnGetEditorViewModel<CommonAspect>(GetEditor);
|
||||
OnUpdateEditorViewModel<CommonAspect>(UpdateEditor);
|
||||
@@ -46,7 +47,7 @@ namespace Orchard.Core.Common.Providers {
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
void DefaultTimestampsAndOwner(CreateContentContext context, CommonAspect instance) {
|
||||
void DefaultTimestampsAndOwner(ActivatedContentContext context, CommonAspect instance) {
|
||||
// assign default create/modified dates
|
||||
if (instance.Record.CreatedUtc == null) {
|
||||
instance.Record.CreatedUtc = _clock.UtcNow;
|
||||
|
@@ -81,24 +81,36 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
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]
|
||||
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 = _contentManager.UpdateEditorViewModel(_contentManager.New<Blog>("blog"), null, this);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
Blog blog = _blogService.Create(model.ToCreateBlogParams());
|
||||
|
||||
_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(blog.Slug));
|
||||
return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug));
|
||||
}
|
||||
|
||||
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.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogProvider : ContentHandler {
|
||||
@@ -16,6 +17,15 @@ namespace Orchard.Blogs.Models {
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||
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>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\BlogPostController.cs" />
|
||||
<Compile Include="Extensions\BlogCreateViewModelExtensions.cs" />
|
||||
<Compile Include="Extensions\BlogPostCreateViewModelExtensions.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
@@ -120,10 +119,11 @@
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogEditViewModel.ascx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogPermalink.ascx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\CreateBlogViewModel.ascx" />
|
||||
<Content Include="Views\Blog\Item.aspx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostSummaryAdmin.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="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -30,14 +30,6 @@ namespace Orchard.Blogs.Services {
|
||||
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) {
|
||||
_blogRepository.Delete(blog.Record);
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ namespace Orchard.Blogs.Services {
|
||||
public interface IBlogService : IDependency {
|
||||
Blog Get(string slug);
|
||||
IEnumerable<Blog> Get();
|
||||
Blog Create(CreateBlogParams parameters);
|
||||
void Delete(Blog blog);
|
||||
}
|
||||
}
|
@@ -1,16 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class CreateBlogViewModel : AdminViewModel {
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public ItemEditorViewModel<Blog> Blog { get; set; }
|
||||
|
||||
//TODO: (erikpo) Need a data type for slug
|
||||
[Required]
|
||||
public string Slug { get; set; }
|
||||
//[Required]
|
||||
//public string Name { 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]
|
||||
//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.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
@@ -6,7 +8,7 @@
|
||||
<h2>Add Blog</h2>
|
||||
<% using (Html.BeginForm()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<%=Html.EditorForModel() %>
|
||||
<%=Html.EditorForItem(vm => vm.Blog) %>
|
||||
<fieldset><input class="button" type="submit" value="Create" /></fieldset>
|
||||
<% } %>
|
||||
<% 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>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Blog>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models" %>
|
||||
<fieldset>
|
||||
<label for="Name">Blog Name</label>
|
||||
<%=Html.EditorFor(m => m.Name) %>
|
Reference in New Issue
Block a user