Skip to content

Instantly share code, notes, and snippets.

@bleroy
Created April 1, 2015 22:10
Show Gist options
  • Save bleroy/b000b3176236a41a9281 to your computer and use it in GitHub Desktop.
Save bleroy/b000b3176236a41a9281 to your computer and use it in GitHub Desktop.
CodePlex Issue #16335 Plain Text Attachments
diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs
--- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs
+++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs
@@ -1,3 +1,4 @@
+using System;
using System.Web.Mvc;
using Orchard.Blogs.Drivers;
using Orchard.Blogs.Extensions;
@@ -8,14 +9,18 @@
using Orchard.Localization;
using Orchard.Mvc.AntiForgery;
using Orchard.Mvc.Results;
+using Orchard.Mvc.ViewModels;
using Orchard.UI.Admin;
using Orchard.UI.Notify;
+using Orchard.Extensions;
namespace Orchard.Blogs.Controllers {
[ValidateInput(false), Admin]
public class BlogPostAdminController : Controller, IUpdateModel {
private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService;
+ private const string PublishLater = "PublishLater";
+ private const string PublishNow = "PublishNow";
public BlogPostAdminController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService) {
Services = services;
@@ -55,6 +60,8 @@
model.BlogPost = Services.ContentManager.UpdateEditorModel(blogPost, this);
+ Validate(model.BlogPost);
+
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();
return View(model);
@@ -64,12 +71,13 @@
Services.ContentManager.UpdateEditorModel(blogPost, this);
// Execute publish command
+
switch (Request.Form["Command"]) {
- case "PublishNow":
+ case PublishNow:
_blogPostService.Publish(model.BlogPost.Item);
Services.Notifier.Information(T("Blog post has been published"));
break;
- case "PublishLater":
+ case PublishLater:
_blogPostService.Publish(model.BlogPost.Item, model.BlogPost.Item.ScheduledPublishUtc.Value);
Services.Notifier.Information(T("Blog post has been scheduled for publishing"));
break;
@@ -81,6 +89,27 @@
return Redirect(Url.BlogPostEdit(model.BlogPost.Item));
}
+ private void Validate(ContentItemViewModel<BlogPost> model) {
+
+ if (Request.Form["Command"] == PublishLater) {
+
+ if (model.Item.ScheduledPublishUtc.HasValue && model.Item.ScheduledPublishUtc.Value < DateTime.Now) {
+ ModelState.AddModelError("ScheduledPublishUtcDate",
+ T("You cannot schedule a publishing date in the past").ToString());
+ }
+
+ if (model.Item.ScheduledPublishUtcDate == "Date" ||
+ model.Item.ScheduledPublishUtcDate.IsNullOrEmptyTrimmed()) {
+ ModelState.AddModelError("ScheduledPublishUtcDate", T("You must select a publishing date").ToString());
+ }
+
+ if (model.Item.ScheduledPublishUtcTime == "Time" ||
+ model.Item.ScheduledPublishUtcTime.IsNullOrEmptyTrimmed()) {
+ ModelState.AddModelError("ScheduledPublishUtcTime", T("You must select a publishing time").ToString());
+ }
+ }
+ }
+
public ActionResult Edit(string blogSlug, int postId) {
if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't edit blog post")))
return new HttpUnauthorizedResult();
@@ -121,6 +150,8 @@
TryUpdateModel(model);
+ Validate(model.BlogPost);
+
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();
return View(model);
diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/EditorTemplates/Parts/Blogs.BlogPost.Publish.ascx b/src/Orchard.Web/Modules/Orchard.Blogs/Views/EditorTemplates/Parts/Blogs.BlogPost.Publish.ascx
--- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/EditorTemplates/Parts/Blogs.BlogPost.Publish.ascx
+++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/EditorTemplates/Parts/Blogs.BlogPost.Publish.ascx
@@ -19,14 +19,17 @@
<label class="forcheckbox" for="Command_PublishNow"><%=_Encoded("Publish Now")%></label>
</div>
<div>
+
<%=Html.RadioButton("Command", "PublishLater", Model.ScheduledPublishUtc != null, new { id = "Command_PublishLater" }) %>
<label class="forcheckbox" for="Command_PublishLater"><%=_Encoded("Publish Later")%></label>
</div>
<div>
<label class="forpicker" for="ScheduledPublishUtcDate"><%=_Encoded("Date")%></label>
<%=Html.EditorFor(m => m.ScheduledPublishUtcDate)%>
+ <%= Html.ValidationMessage("ScheduledPublishUtcDate")%>
<label class="forpicker" for="ScheduledPublishUtcTime"><%=_Encoded("Time")%></label>
<%=Html.EditorFor(m => m.ScheduledPublishUtcTime)%>
+ <%= Html.ValidationMessage("ScheduledPublishUtcTime")%>
</div>
</fieldset>
<script type="text/javascript">$(function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment