ViewBug page

This commit is contained in:
Michael 2017-04-14 17:32:04 -04:00
parent dc233f9db9
commit e63b7b343b
4 changed files with 131 additions and 0 deletions

View file

@ -3,6 +3,7 @@
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 @@ public ActionResult ViewCategory(string id)
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);
}
}
}

View file

@ -33,6 +33,16 @@ public ForumPost[] Comments
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; }

View file

@ -565,6 +565,7 @@
<Content Include="Views\Bugs\_BugBar.cshtml" />
<Content Include="Views\Bugs\_Sidebar.cshtml" />
<Content Include="Views\Bugs\ViewCategory.cshtml" />
<Content Include="Views\Bugs\ViewBug.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />

View file

@ -0,0 +1,88 @@
@model Project_Unite.Models.ViewBugViewModel
@{
ViewBag.Title = Model.BugData.Name + " - Bugs";
var tags = new Project_Unite.Models.ApplicationDbContext().BugTags;
}
<h2>Bugtracker</h2>
@{
Html.RenderPartial("~/Views/Bugs/_BugBar.cshtml");
}
<div class="row">
<div class="col-xs-3">
@{
Html.RenderPartial("~/Views/Bugs/_Sidebar.cshtml", tags);
}
</div>
<div class="col-xs-9">
<h3>@Model.BugData.Name</h3>
<p>
Opened by <strong>@Html.UserLink(Model.BugData.Reporter)</strong> at <strong>@Model.BugData.ReportedAt</strong> &bull;
@if (Model.BugData.Open)
{
<strong>Open</strong>
}
else
{
<strong>Closed by @Html.UserLink(Model.BugData.ClosedBy) at @Model.BugData.ClosedAt </strong>
}
&bull;
@switch (Model.BugData.Urgency)
{
case 0:
<strong>Minor</strong>
break;
case 1:
<strong>Moderate</strong>
break;
case 2:
<strong>Major</strong>
break;
case 3:
<strong>Critical</strong>
break;
default:
<strong>A bug occurred in the bugtracker. Urgency unknown.</strong>
break;
}
</p>
@foreach(var post in Model.BugData.Comments.OrderBy(x=>x.PostedAt))
{
<div class="panel panel-default">
<div class="panel-body">
<p>@Html.UserLink(post.AuthorId) at @post.PostedAt</p>
<hr/>
<p>@Html.Markdown(post.Body)</p>
</div>
</div>
}
<hr/>
@using (Html.BeginForm())
{
<div class="panel panel-default">
<div class="panel-body">
<h4>Post a comment</h4>
@Html.AntiForgeryToken()
<div class="panel panel-danger">
<div class="panel-body">
@Html.ValidationSummary()
</div>
</div>
@Html.TextAreaFor(Model=>Model.Comment, new { @class="form-control", rows="5"})
<p><input type="submit" class="btn btn-primary" value="Post" /> Markdown is supported.</p>
</div>
</div>
}
</div>
</div>