summaryrefslogtreecommitdiff
path: root/Project-Unite/Controllers/BugsController.cs
blob: d7ee4e2c70240c5f74bcd84fe6389e34684bb452 (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
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);
        }
    }
}