diff --git a/Teknik/Areas/Blog/BlogAreaRegistration.cs b/Teknik/Areas/Blog/BlogAreaRegistration.cs index 279dd34..8eaab78 100644 --- a/Teknik/Areas/Blog/BlogAreaRegistration.cs +++ b/Teknik/Areas/Blog/BlogAreaRegistration.cs @@ -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 } ); diff --git a/Teknik/Areas/Blog/Controllers/BlogController.cs b/Teknik/Areas/Blog/Controllers/BlogController.cs index 5917752..5d1d125 100644 --- a/Teknik/Areas/Blog/Controllers/BlogController.cs +++ b/Teknik/Areas/Blog/Controllers/BlogController.cs @@ -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)) + { + blog = db.Blogs.Find(Constants.SERVERBLOGID); + } + 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); } - if (id == 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 new HttpStatusCodeResult(HttpStatusCode.BadRequest); + 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); } - Models.Blog blog = db.Blogs.Find(id); - if (blog == null) - { - return HttpNotFound(); - } - 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); - } } } diff --git a/Teknik/Areas/Blog/Models/Blog.cs b/Teknik/Areas/Blog/Models/Blog.cs index bc65c8b..082b7d1 100644 --- a/Teknik/Areas/Blog/Models/Blog.cs +++ b/Teknik/Areas/Blog/Models/Blog.cs @@ -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 Posts { get; set; } diff --git a/Teknik/Areas/Blog/ViewModels/BlogViewModel.cs b/Teknik/Areas/Blog/ViewModels/BlogViewModel.cs index 62a44c9..9ef2781 100644 --- a/Teknik/Areas/Blog/ViewModels/BlogViewModel.cs +++ b/Teknik/Areas/Blog/ViewModels/BlogViewModel.cs @@ -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 Posts { get; set; } diff --git a/Teknik/Areas/Blog/ViewModels/PostViewModel.cs b/Teknik/Areas/Blog/ViewModels/PostViewModel.cs new file mode 100644 index 0000000..bbf7a46 --- /dev/null +++ b/Teknik/Areas/Blog/ViewModels/PostViewModel.cs @@ -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 Tags { get; set; } + } +} \ No newline at end of file diff --git a/Teknik/Areas/Blog/Views/Blog/Index.cshtml b/Teknik/Areas/Blog/Views/Blog/Blog.cshtml similarity index 100% rename from Teknik/Areas/Blog/Views/Blog/Index.cshtml rename to Teknik/Areas/Blog/Views/Blog/Blog.cshtml diff --git a/Teknik/Areas/Blog/Views/Blog/Post.cshtml b/Teknik/Areas/Blog/Views/Blog/Post.cshtml new file mode 100644 index 0000000..ee40df8 --- /dev/null +++ b/Teknik/Areas/Blog/Views/Blog/Post.cshtml @@ -0,0 +1,53 @@ +@model Teknik.Areas.Blog.Models.Post + +
+
+
+

@Model.Title

+ +

@Model.Article

+
+
+
+ +
+
+

There are currently no articles.

+
+
\ No newline at end of file diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 030bf1d..5d5db58 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -141,6 +141,7 @@ + @@ -203,7 +204,7 @@ - + @@ -234,6 +235,7 @@ + diff --git a/Teknik/ViewModels/ViewModelBase.cs b/Teknik/ViewModels/ViewModelBase.cs index d1113f8..00642b1 100644 --- a/Teknik/ViewModels/ViewModelBase.cs +++ b/Teknik/ViewModels/ViewModelBase.cs @@ -7,18 +7,5 @@ namespace Teknik.ViewModels { public abstract class ViewModelBase { - private Config _config; - - public Config Config - { - get - { - return _config; - } - set - { - _config = value; - } - } } } \ No newline at end of file