mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Getting blog edit into the same state as create
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043583
This commit is contained in:
@@ -86,11 +86,15 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
Blog blog = _contentManager.New<Blog>("blog");
|
||||
CreateBlogViewModel viewModel = new CreateBlogViewModel {
|
||||
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new CreateBlogViewModel {
|
||||
Blog = _contentManager.GetEditorViewModel(blog, null)
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -114,14 +118,20 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
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 = blog };
|
||||
model.ItemView = _contentManager.GetEditorViewModel(model.Blog.ContentItem, "");
|
||||
var model = new BlogEditViewModel {
|
||||
Blog = _contentManager.GetEditorViewModel(blog, "")
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -136,11 +146,11 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel { Blog = blog };
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(model.Blog.ContentItem, "", this);
|
||||
var model = new BlogEditViewModel {
|
||||
Blog = _contentManager.UpdateEditorViewModel(blog, "", this)
|
||||
};
|
||||
|
||||
IValueProvider values = input.ToValueProvider();
|
||||
if (!TryUpdateModel(model, values))
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
_notifier.Information(T("Blog information updated"));
|
||||
|
@@ -117,7 +117,6 @@
|
||||
<Content Include="Views\BlogPost\Item.aspx" />
|
||||
<Content Include="Views\Blog\Create.aspx" />
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogEditViewModel.ascx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogPermalink.ascx" />
|
||||
<Content Include="Views\Blog\Item.aspx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostSummaryAdmin.ascx" />
|
||||
|
@@ -2,41 +2,11 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogEditViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
get { return Blog.Id; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Name {
|
||||
get { return Blog.As<RoutableAspect>().Record.Title; }
|
||||
set { Blog.As<RoutableAspect>().Record.Title = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Slug {
|
||||
get { return Blog.As<RoutableAspect>().Record.Slug; }
|
||||
set { Blog.As<RoutableAspect>().Record.Slug = value; }
|
||||
}
|
||||
|
||||
public string Description {
|
||||
get { return Blog.Record.Description; }
|
||||
set { Blog.Record.Description = value; }
|
||||
}
|
||||
|
||||
//public bool Enabled {
|
||||
// get { return Blog.As<Blog>().Record.Enabled; }
|
||||
// set { Blog.As<Blog>().Record.Enabled = value; }
|
||||
//}
|
||||
public ItemEditorViewModel<Blog> Blog { get; set; }
|
||||
}
|
||||
}
|
@@ -1,9 +1,6 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<CreateBlogViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Security" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<% Html.Include("AdminHead"); %>
|
||||
<h2>Add Blog</h2>
|
||||
<% using (Html.BeginForm()) { %>
|
||||
|
@@ -1,12 +1,11 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<% Html.Include("AdminHead"); %>
|
||||
<h2>Edit Blog</h2>
|
||||
<% using (Html.BeginForm()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<%=Html.EditorForModel() %>
|
||||
<%=Html.EditorForItem(m => m.Blog) %>
|
||||
<fieldset><input class="button" type="submit" value="Save" /></fieldset>
|
||||
<% } %>
|
||||
<% Html.Include("AdminFoot"); %>
|
@@ -1,11 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BlogEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<fieldset>
|
||||
<label for="Name">Blog Name</label>
|
||||
<%=Html.EditorFor(m => m.Name) %>
|
||||
</fieldset>
|
||||
<%=Html.EditorFor(m => m.Slug, "BlogPermalink") %>
|
||||
<fieldset>
|
||||
<label for="Description">Description</label>
|
||||
<%=Html.TextAreaFor(m => m.Description, 5, 60, null) %>
|
||||
</fieldset>
|
Reference in New Issue
Block a user