blob: 2d9250fad675d447e616e0c4435639dbf0d35710 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
using System;
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
{
public class BugsController : Controller
{
// GET: Bugs
public ActionResult Index()
{
var db = new ApplicationDbContext();
return View(db.BugTags);
}
public ActionResult ViewCategory(string id)
{
var db = new ApplicationDbContext();
var cat = db.BugTags.FirstOrDefault(x => x.Id == id);
if (cat == null)
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);
}
[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 });
}
}
}
|