From 344985e14a5103b9bf18d677f22e45e69ddac5dd Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Sat, 19 Dec 2015 00:36:30 -0800 Subject: [PATCH] Changed login url --- Teknik/Areas/Blog/Controllers/BlogController.cs | 22 +++++++++++++++++++++- Teknik/Areas/Blog/Scripts/Blog.js | 12 ++++++------ Teknik/Areas/Blog/Views/Blog/Posts.cshtml | 15 ++------------- Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml | 2 +- .../Areas/Profile/Controllers/ProfileController.cs | 3 ++- Teknik/Web.config | 4 +++- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Teknik/Areas/Blog/Controllers/BlogController.cs b/Teknik/Areas/Blog/Controllers/BlogController.cs index aba579d..3ca0462 100644 --- a/Teknik/Areas/Blog/Controllers/BlogController.cs +++ b/Teknik/Areas/Blog/Controllers/BlogController.cs @@ -164,7 +164,27 @@ namespace Teknik.Areas.Blog.Controllers } return Json(new { error = "No post found" }); } - + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult PublishPost(int postID, bool publish) + { + if (ModelState.IsValid) + { + Post post = db.Posts.Find(postID); + if (post != null) + { + post.Published = publish; + if (publish) + post.DatePublished = DateTime.Now; + db.Entry(post).State = EntityState.Modified; + db.SaveChanges(); + return Json(new { result = true }); + } + } + return Json(new { error = "No post found" }); + } + [HttpPost] [ValidateAntiForgeryToken] public ActionResult DeletePost(int postID) diff --git a/Teknik/Areas/Blog/Scripts/Blog.js b/Teknik/Areas/Blog/Scripts/Blog.js index 0812961..0557da7 100644 --- a/Teknik/Areas/Blog/Scripts/Blog.js +++ b/Teknik/Areas/Blog/Scripts/Blog.js @@ -205,14 +205,14 @@ function linkPostUnpublish(selector) { $.ajax({ type: "POST", url: publishPostURL, - data: AddAntiForgeryToken({ publish: false, postID: post_id }), + data: AddAntiForgeryToken({ postID: post_id, publish: false }), success: function (html) { - if (html == 'true') { + if (html.result) { window.location.reload(); } else { $("#top_msg").css('display', 'inline', 'important'); - $("#top_msg").html('
' + html + '
'); + $("#top_msg").html('
' + html.error + '
'); } } }); @@ -226,14 +226,14 @@ function linkPostPublish(selector) { $.ajax({ type: "POST", url: publishPostURL, - data: AddAntiForgeryToken({ publish: true, postID: post_id }), + data: AddAntiForgeryToken({postID: post_id, publish: true }), success: function (html) { - if (html == 'true') { + if (html.result) { window.location.reload(); } else { $("#top_msg").css('display', 'inline', 'important'); - $("#top_msg").html('
' + html + '
'); + $("#top_msg").html('
' + html.error + '
'); } } }); diff --git a/Teknik/Areas/Blog/Views/Blog/Posts.cshtml b/Teknik/Areas/Blog/Views/Blog/Posts.cshtml index 9dcab03..a15e8f5 100644 --- a/Teknik/Areas/Blog/Views/Blog/Posts.cshtml +++ b/Teknik/Areas/Blog/Views/Blog/Posts.cshtml @@ -1,17 +1,6 @@ @model List -@if (Model.Any()) +@foreach (var post in Model) { - foreach (var post in Model) - { - @Html.Partial("Post", post) - } -} -else -{ -
-
-

There are currently no articles.

-
-
+ @Html.Partial("Post", post) } \ No newline at end of file diff --git a/Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml b/Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml index c494e11..de4dba5 100644 --- a/Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml +++ b/Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml @@ -131,7 +131,7 @@ } -
+