diff options
| author | Michael <[email protected]> | 2017-04-14 17:54:26 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-14 17:54:26 -0400 |
| commit | a2cbddfbfdbf385547484aa5edc208ebdbba334a (patch) | |
| tree | 8103d9c250b5bf708d0916a4a26abe0cb6bc3c7d /Project-Unite/Controllers | |
| parent | e63b7b343b56c0170ee7dedd9eea3773ac302350 (diff) | |
| download | project-unite-a2cbddfbfdbf385547484aa5edc208ebdbba334a.tar.gz project-unite-a2cbddfbfdbf385547484aa5edc208ebdbba334a.tar.bz2 project-unite-a2cbddfbfdbf385547484aa5edc208ebdbba334a.zip | |
You can now post bugs.
Well, there's no categories to post them in, yet.
Diffstat (limited to 'Project-Unite/Controllers')
| -rw-r--r-- | Project-Unite/Controllers/BugsController.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/BugsController.cs b/Project-Unite/Controllers/BugsController.cs index d7ee4e2..2d9250f 100644 --- a/Project-Unite/Controllers/BugsController.cs +++ b/Project-Unite/Controllers/BugsController.cs @@ -56,5 +56,79 @@ namespace Project_Unite.Controllers model.Comment = ""; return View(model); } + + [Authorize] + public ActionResult OpenBug(string id) + { + var db = new ApplicationDbContext(); + var bug = db.Bugs.FirstOrDefault(x => x.Id == id); + if (bug == null) + return new HttpStatusCodeResult(404); + bug.Open = true; + db.SaveChanges(); + return RedirectToAction("ViewCategory", new { id = bug.Species }); + } + + [Authorize] + public ActionResult CloseBug(string id) + { + var db = new ApplicationDbContext(); + var bug = db.Bugs.FirstOrDefault(x => x.Id == id); + if (bug == null) + return new HttpStatusCodeResult(404); + bug.Open = false; + bug.ClosedAt = DateTime.Now; + bug.ClosedBy = User.Identity.GetUserId(); + db.SaveChanges(); + return RedirectToAction("ViewCategory", new { id = bug.Species }); + } + + [Authorize] + public ActionResult PostBug() + { + var model = new PostBugViewModel(); + return View(model); + } + + [Authorize] + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult PostBug(PostBugViewModel model) + { + if (!ModelState.IsValid) + return View(model); + var db = new ApplicationDbContext(); + var bug = new Bug(); + bug.Name = model.Name; + + string allowed = "abcdefghijklmnopqrstuvwxyz1234567890_-"; + + string id = bug.Name.ToLower() + "_" + db.Bugs.Count().ToString(); + + foreach(var c in id.ToCharArray()) + { + if (!allowed.Contains(c)) + id = id.Replace(c, '_'); + } + + bug.Id = id; + bug.Open = true; + bug.Reporter = User.Identity.GetUserId(); + bug.ReportedAt = DateTime.Now; + bug.Species = model.SpeciesId; + bug.Urgency = int.Parse(model.Urgency); + bug.ReleaseId = model.VersionId; + var comment = new ForumPost(); + comment.AuthorId = User.Identity.GetUserId(); + comment.Body = model.Description; + comment.Id = Guid.NewGuid().ToString(); + comment.Parent = bug.Id; + comment.PostedAt = DateTime.Now; + db.ForumPosts.Add(comment); + db.Bugs.Add(bug); + db.SaveChanges(); + + return RedirectToAction("ViewBug", new { id = bug.Id }); + } } }
\ No newline at end of file |
