diff --git a/Project-Unite/Controllers/BugsController.cs b/Project-Unite/Controllers/BugsController.cs index 34de971..d7ee4e2 100644 --- a/Project-Unite/Controllers/BugsController.cs +++ b/Project-Unite/Controllers/BugsController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers @@ -24,5 +25,36 @@ namespace Project_Unite.Controllers return new HttpStatusCodeResult(404); return View(cat); } + + public ActionResult ViewBug(string id) + { + var db = new ApplicationDbContext(); + var bug = db.Bugs.FirstOrDefault(x => x.Id == id); + if (bug == null) + return new HttpStatusCodeResult(404); + var model = new ViewBugViewModel(); + model.BugData = bug; + return View(model); + } + + [HttpPost] + [ValidateAntiForgeryToken] + [Authorize] + public ActionResult ViewBug(ViewBugViewModel model) + { + if (!ModelState.IsValid) + return View(model); + var db = new ApplicationDbContext(); + var post = new ForumPost(); + post.Id = Guid.NewGuid().ToString(); + post.AuthorId = User.Identity.GetUserId(); + post.Body = model.Comment; + post.Parent = model.BugData.Id; + post.PostedAt = DateTime.Now; + db.ForumPosts.Add(post); + db.SaveChanges(); + model.Comment = ""; + return View(model); + } } } \ No newline at end of file diff --git a/Project-Unite/Models/BugModels.cs b/Project-Unite/Models/BugModels.cs index 9a6b0ad..0ccca4a 100644 --- a/Project-Unite/Models/BugModels.cs +++ b/Project-Unite/Models/BugModels.cs @@ -33,6 +33,16 @@ namespace Project_Unite.Models public string ClosedBy { get; set; } } + public class ViewBugViewModel + { + public Bug BugData { get; set; } + + [AllowHtml] + [Required(AllowEmptyStrings =false, ErrorMessage ="Please enter a valid comment.")] + [MinLength(20, ErrorMessage = "Your comment must have at least 20 characters.")] + public string Comment { get; set; } + } + public class BugTag { public string Id { get; set; } diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 4d72118..f7e54ed 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -565,6 +565,7 @@ + diff --git a/Project-Unite/Views/Bugs/ViewBug.cshtml b/Project-Unite/Views/Bugs/ViewBug.cshtml new file mode 100644 index 0000000..aee1fcc --- /dev/null +++ b/Project-Unite/Views/Bugs/ViewBug.cshtml @@ -0,0 +1,88 @@ +@model Project_Unite.Models.ViewBugViewModel +@{ + ViewBag.Title = Model.BugData.Name + " - Bugs"; + var tags = new Project_Unite.Models.ApplicationDbContext().BugTags; +} + + + +

Bugtracker

+ +@{ + Html.RenderPartial("~/Views/Bugs/_BugBar.cshtml"); +} + +
+
+ @{ + Html.RenderPartial("~/Views/Bugs/_Sidebar.cshtml", tags); + } +
+ +
+

@Model.BugData.Name

+ +

+ Opened by @Html.UserLink(Model.BugData.Reporter) at @Model.BugData.ReportedAt • + @if (Model.BugData.Open) + { + Open + } + else + { + Closed by @Html.UserLink(Model.BugData.ClosedBy) at @Model.BugData.ClosedAt + } + • + @switch (Model.BugData.Urgency) + { + case 0: + Minor + break; + case 1: + Moderate + break; + case 2: + Major + break; + case 3: + Critical + break; + default: + A bug occurred in the bugtracker. Urgency unknown. + break; + } + +

+ + @foreach(var post in Model.BugData.Comments.OrderBy(x=>x.PostedAt)) + { +
+
+

@Html.UserLink(post.AuthorId) at @post.PostedAt

+
+

@Html.Markdown(post.Body)

+
+
+ } +
+ @using (Html.BeginForm()) + { +
+
+

Post a comment

+ + @Html.AntiForgeryToken() +
+
+ @Html.ValidationSummary() +
+
+ + @Html.TextAreaFor(Model=>Model.Comment, new { @class="form-control", rows="5"}) +

Markdown is supported.

+
+
+ } + +
+
\ No newline at end of file