@@ -16,31 +16,31 @@ namespace Teknik.Areas.Blog | |||
public override void RegisterArea(AreaRegistrationContext context) | |||
{ | |||
context.MapSubdomainRoute( | |||
"Blog_dev_index", // Route name | |||
"Blog_dev_blog", // Route name | |||
"dev", | |||
"Blog", // URL with parameters | |||
new { controller = "Blog", action = "Index" }, // Parameter defaults | |||
"Blog/{username}", // URL with parameters | |||
new { controller = "Blog", action = "Blog", username = UrlParameter.Optional }, // Parameter defaults | |||
new[] { typeof(Controllers.BlogController).Namespace } | |||
); | |||
context.MapSubdomainRoute( | |||
"Blog_dev_detail", // Route name | |||
"Blog_dev_post", // Route name | |||
"dev", | |||
"Blog/{username}/{id}", // URL with parameters | |||
new { controller = "Blog", action = "Details", username = "", id = UrlParameter.Optional }, // Parameter defaults | |||
new { controller = "Blog", action = "Post", username = "", id = 0 }, // Parameter defaults | |||
new[] { typeof(Controllers.BlogController).Namespace } | |||
); | |||
context.MapSubdomainRoute( | |||
"Blog_default_index", // Route name | |||
"Blog_default_blog", // Route name | |||
"blog", | |||
"", // URL with parameters | |||
new { controller = "Blog", action = "Index" }, // Parameter defaults | |||
"{username}", // URL with parameters | |||
new { controller = "Blog", action = "Blog", username = UrlParameter.Optional }, // Parameter defaults | |||
new[] { typeof(Controllers.BlogController).Namespace } | |||
); | |||
context.MapSubdomainRoute( | |||
"Blog_default_detail", // Route name | |||
"Blog_default_post", // Route name | |||
"blog", | |||
"{username}/{id}", // URL with parameters | |||
new { controller = "Blog", action = "Details", username = "", id = UrlParameter.Optional }, // Parameter defaults | |||
new { controller = "Blog", action = "Post", username = "", id = 0 }, // Parameter defaults | |||
new[] { typeof(Controllers.BlogController).Namespace } | |||
); | |||
@@ -6,7 +6,9 @@ using System.Linq; | |||
using System.Net; | |||
using System.Web; | |||
using System.Web.Mvc; | |||
using Teknik.Areas.Blog.Models; | |||
using Teknik.Areas.Blog.ViewModels; | |||
using Teknik.Areas.Profile.Models; | |||
using Teknik.Controllers; | |||
using Teknik.Helpers; | |||
using Teknik.Models; | |||
@@ -39,22 +41,69 @@ namespace Teknik.Areas.Blog.Controllers | |||
// GET: Blogs/Details/5 | |||
[AllowAnonymous] | |||
public ActionResult Details(string username, int? id) | |||
public ActionResult Blog(string username) | |||
{ | |||
Models.Blog blog = null; | |||
if (string.IsNullOrEmpty(username)) | |||
{ | |||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); | |||
blog = db.Blogs.Find(Constants.SERVERBLOGID); | |||
} | |||
if (id == null) | |||
else | |||
{ | |||
var blogs = db.Blogs.Include("Blog.User").Where(p => p.User.Username == username); | |||
if (blogs.Any()) | |||
{ | |||
blog = blogs.First(); | |||
} | |||
} | |||
// find the post specified | |||
if (blog != null) | |||
{ | |||
BlogViewModel model = new BlogViewModel(); | |||
model.BlogId = blog.BlogId; | |||
model.UserId = blog.UserId; | |||
model.User = blog.User; | |||
model.Posts = blog.Posts; | |||
return View(model); | |||
} | |||
return new HttpStatusCodeResult(HttpStatusCode.NotFound); | |||
} | |||
// GET: Blogs/Details/5 | |||
[AllowAnonymous] | |||
public ActionResult Post(string username, int id) | |||
{ | |||
if (string.IsNullOrEmpty(username)) | |||
{ | |||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); | |||
} | |||
Models.Blog blog = db.Blogs.Find(id); | |||
if (blog == null) | |||
// find the post specified | |||
var post = db.Posts.Include("Blog").Include("Blog.User").Where(p => p.Blog.User.Username == username && p.PostId == id); | |||
if (post.Any()) | |||
{ | |||
return HttpNotFound(); | |||
Post curPost = post.First(); | |||
PostViewModel model = new PostViewModel(); | |||
model.BlogId = curPost.BlogId; | |||
model.PostId = curPost.PostId; | |||
model.DatePosted = curPost.DatePosted; | |||
model.Published = curPost.Published; | |||
model.DatePublished = curPost.DatePublished; | |||
model.Title = curPost.Title; | |||
model.Tags = curPost.Tags; | |||
model.Article = curPost.Article; | |||
return View(model); | |||
} | |||
return View(blog); | |||
return new HttpStatusCodeResult(HttpStatusCode.NotFound); | |||
} | |||
public ActionResult GetPosts(int blogID, int startPostID, int count) | |||
{ | |||
object model = null; | |||
return PartialView("Post", model); | |||
} | |||
// GET: Blogs/Create | |||
@@ -136,14 +185,5 @@ namespace Teknik.Areas.Blog.Controllers | |||
db.SaveChanges(); | |||
return RedirectToAction("Index"); | |||
} | |||
protected override void Dispose(bool disposing) | |||
{ | |||
if (disposing) | |||
{ | |||
db.Dispose(); | |||
} | |||
base.Dispose(disposing); | |||
} | |||
} | |||
} |
@@ -10,6 +10,10 @@ namespace Teknik.Areas.Blog.Models | |||
public int UserId { get; set; } | |||
public string Title { get; set; } | |||
public string Description { get; set; } | |||
public User User { get; set; } | |||
public List<Post> Posts { get; set; } |
@@ -14,6 +14,10 @@ namespace Teknik.Areas.Blog.ViewModels | |||
public int UserId { get; set; } | |||
public string Title { get; set; } | |||
public string Description { get; set; } | |||
public User User { get; set; } | |||
public List<Post> Posts { get; set; } |
@@ -0,0 +1,27 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Teknik.Areas.Blog.Models; | |||
using System.Linq; | |||
using System.Web; | |||
namespace Teknik.Areas.Blog.ViewModels | |||
{ | |||
public class PostViewModel | |||
{ | |||
public int PostId { get; set; } | |||
public int BlogId { get; set; } | |||
public DateTime DatePosted { get; set; } | |||
public DateTime DatePublished { get; set; } | |||
public bool Published { get; set; } | |||
public string Title { get; set; } | |||
public string Article { get; set; } | |||
public List<string> Tags { get; set; } | |||
} | |||
} |
@@ -0,0 +1,53 @@ | |||
@model Teknik.Areas.Blog.Models.Post | |||
<script> | |||
var converter = new Markdown.getSanitizingConverter(); | |||
// Title Conversion | |||
var old_post = $("#title_@Model.PostId").text(); | |||
var new_post = converter.makeHtml(old_post); | |||
$("#title_@Model.PostId").html(new_post); | |||
// Post Conversion | |||
var old_post = $("#post_@Model.PostId").text(); | |||
var new_post = converter.makeHtml(old_post); | |||
$("#post_@Model.PostId").html(new_post); | |||
</script> | |||
<div class="row"> | |||
<div class="col-sm-10 col-sm-offset-1"> | |||
<div class="blog-post"> | |||
<h2 class="blog-post-title text-center"><a href="@Url.Action("Post", "Blog", new { area = "Blog", username = Model.Blog.User.Username, id = Model.PostId })" id="title_@Model.PostId">@Model.Title</a></h2> | |||
<p class="blog-post-meta text-center text-muted"> | |||
Posted on @Model.DatePublished.ToString("F d, Y") by <a href="@Url.Action("Index", "Profile", new { area = "Profile" })/@Model.Blog.User.Username">@Model.Blog.User.Username</a> | |||
<?php | |||
if ($own_blog) | |||
{ | |||
?> | |||
<br /> | |||
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button> | |||
<?php | |||
if ($published) | |||
{ | |||
?> | |||
<button type="button" class="btn btn-warning unpublish_post" id="<?php echo $post_id; ?>">Unpublish</button> | |||
<?php | |||
} | |||
else | |||
{ | |||
?> | |||
<button type="button" class="btn btn-success publish_post" id="<?php echo $post_id; ?>">Publish</button> | |||
<?php | |||
} | |||
?> | |||
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button> | |||
<?php | |||
} | |||
?> | |||
</p> | |||
<p id="post_@Model.PostId">@Model.Article</p> | |||
</div> | |||
</div> | |||
</div> | |||
<!-- NO POSTS --> | |||
<div class="row"> | |||
<div class="col-sm-12 text-center"> | |||
<h2>There are currently no articles.</h2> | |||
</div> | |||
</div> |
@@ -141,6 +141,7 @@ | |||
<Compile Include="Areas\About\Controllers\AboutController.cs" /> | |||
<Compile Include="Areas\Blog\BlogAreaRegistration.cs" /> | |||
<Compile Include="Areas\Blog\ViewModels\BlogViewModel.cs" /> | |||
<Compile Include="Areas\Blog\ViewModels\PostViewModel.cs" /> | |||
<Compile Include="Areas\Contact\ContactAreaRegistration.cs" /> | |||
<Compile Include="Areas\Contact\Controllers\ContactController.cs" /> | |||
<Compile Include="Areas\Contact\Models\Contact.cs" /> | |||
@@ -203,7 +204,7 @@ | |||
<Content Include="App_Data\Config.json" /> | |||
<Content Include="ConnectionStrings.config" /> | |||
<Content Include="Areas\Blog\Views\web.config" /> | |||
<Content Include="Areas\Blog\Views\Blog\Index.cshtml" /> | |||
<Content Include="Areas\Blog\Views\Blog\Blog.cshtml" /> | |||
<Content Include="Areas\Dev\Views\web.config" /> | |||
<Content Include="Areas\Home\Views\web.config" /> | |||
<Content Include="Areas\Home\Views\_ViewStart.cshtml" /> | |||
@@ -234,6 +235,7 @@ | |||
<Content Include="Content\bootstrap.css.map" /> | |||
<Content Include="Content\bootstrap-theme.min.css.map" /> | |||
<Content Include="Content\bootstrap-theme.css.map" /> | |||
<Content Include="Areas\Blog\Views\Blog\Post.cshtml" /> | |||
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" /> | |||
<None Include="Scripts\jquery-2.1.4.intellisense.js" /> | |||
<Content Include="Scripts\bootstrap.js" /> |
@@ -7,18 +7,5 @@ namespace Teknik.ViewModels | |||
{ | |||
public abstract class ViewModelBase | |||
{ | |||
private Config _config; | |||
public Config Config | |||
{ | |||
get | |||
{ | |||
return _config; | |||
} | |||
set | |||
{ | |||
_config = value; | |||
} | |||
} | |||
} | |||
} |