From 588d21569c6a6adfcb9a75c29c57c43dc7954f06 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 17 May 2017 16:23:55 -0400 Subject: [PATCH] individual post subjects --- Project-Unite/Controllers/ForumController.cs | 1 + Project-Unite/Models/ForumCategory.cs | 2 ++ Project-Unite/Views/Forum/PostReply.cshtml | 6 +++++- Project-Unite/Views/Forum/ViewForum.cshtml | 17 +++++++++++++++++ Project-Unite/Views/Forum/ViewTopic.cshtml | 10 ++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Project-Unite/Controllers/ForumController.cs b/Project-Unite/Controllers/ForumController.cs index 3eb3c83..888c41e 100644 --- a/Project-Unite/Controllers/ForumController.cs +++ b/Project-Unite/Controllers/ForumController.cs @@ -47,6 +47,7 @@ namespace Project_Unite.Controllers var model = new CreateTopicViewModel(); model.Category = id; + model.Subject = new ApplicationDbContext().ForumTopics.FirstOrDefault(x => x.Discriminator == id).Subject; return View(model); } diff --git a/Project-Unite/Models/ForumCategory.cs b/Project-Unite/Models/ForumCategory.cs index 52e184e..96c826e 100644 --- a/Project-Unite/Models/ForumCategory.cs +++ b/Project-Unite/Models/ForumCategory.cs @@ -50,6 +50,8 @@ namespace Project_Unite.Models public class ForumPost { public string Id { get; set; } + + public string Subject { get; set; } [Required] public string Parent { get; set; } diff --git a/Project-Unite/Views/Forum/PostReply.cshtml b/Project-Unite/Views/Forum/PostReply.cshtml index 2305204..6080a79 100644 --- a/Project-Unite/Views/Forum/PostReply.cshtml +++ b/Project-Unite/Views/Forum/PostReply.cshtml @@ -12,7 +12,11 @@ - + + + + diff --git a/Project-Unite/Views/Forum/ViewForum.cshtml b/Project-Unite/Views/Forum/ViewForum.cshtml index e4b528f..92fb802 100644 --- a/Project-Unite/Views/Forum/ViewForum.cshtml +++ b/Project-Unite/Views/Forum/ViewForum.cshtml @@ -37,6 +37,18 @@ } } +@{ + var db = new Project_Unite.Models.ApplicationDbContext(); + var globals = Model.Topics.Where(x => x.ShouldShow == true&&x.IsGlobal==true).OrderByDescending(x => x.StartedAt); + +} + +@if (globals.Count() > 0) +{ +
+ +} +
@if (Model.Topics.Length > 0) @@ -58,6 +70,11 @@
@topic.Posts.Length
+
+ @topic.Posts.OrderByDescending(x => x.PostedAt).First().Subject
+ by @Html.UserLink(topic.Posts.OrderByDescending(x => x.PostedAt).First().AuthorId)
+ at @topic.Posts.OrderByDescending(x => x.PostedAt).First().PostedAt +
} } diff --git a/Project-Unite/Views/Forum/ViewTopic.cshtml b/Project-Unite/Views/Forum/ViewTopic.cshtml index ed6b7c0..61ef682 100644 --- a/Project-Unite/Views/Forum/ViewTopic.cshtml +++ b/Project-Unite/Views/Forum/ViewTopic.cshtml @@ -3,6 +3,16 @@ @using Microsoft.AspNet.Identity @{ ViewBag.Title = Model.Subject; + var db = new Project_Unite.Models.ApplicationDbContext(); + var posts = db.ForumPosts.Where(x => x.Parent == Model.Id); + foreach(var post in posts.ToArray()) + { + if (string.IsNullOrWhiteSpace(post.Subject)) + { + post.Subject = Model.Subject; + } + } + db.SaveChanges(); }
@Html.DisplayNameFor(Model => Model.Body) + Subject:@Html.TextBoxFor(Model=>Model.Subject, new{@class="form-control"})
@Html.DisplayNameFor(Model => Model.Body)

This is the content of your topic. You can use Markdown formatting to style your post.

@Html.TextAreaFor(Model => Model.Body, new { @class = "form-control", style = "width:100%", rows = "10" })