Exemplo n.º 1
0
        //GET: Bug/Edit
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var database = new BugsTrackerDbContext())
            {
                var bug = database.Bugs
                          .Where(b => b.Id == id)
                          .First();

                if (bug == null)
                {
                    return(HttpNotFound());
                }

                var model = new BugViewModel();
                model.Id          = bug.Id;
                model.Title       = bug.Title;
                model.Description = bug.Description;
                model.State       = bug.State;
                model.RadioButton = bug.RadioButton;

                return(View(model));
            }
        }
Exemplo n.º 2
0
        // GET: Search for bugs with state Fixed
        public ActionResult Fixed()
        {
            var db        = new BugsTrackerDbContext();
            var fixedBugs = db.Bugs
                            .Where(a => a.State == State.Fixed)
                            .ToList();

            return(View(fixedBugs));
        }
Exemplo n.º 3
0
        // GET: Search for bugs with state Open
        public ActionResult Open()
        {
            var db       = new BugsTrackerDbContext();
            var openBugs = db.Bugs
                           .Where(a => a.State == State.Open)
                           .ToList();

            return(View(openBugs));
        }
Exemplo n.º 4
0
 // GET: Search for bugs with state New
 public ActionResult New()
 {
     using (var db = new BugsTrackerDbContext())
     {
         var newBugs = db.Bugs
                       .Where(a => a.State == State.New)
                       .ToList();
         return(View(newBugs));
     }
 }
Exemplo n.º 5
0
        public ActionResult SubstringSearch(string input)
        {
            var db          = new BugsTrackerDbContext();
            var foundedBugs = db.Bugs
                              .Where(b => b.Title.Contains(input))
                              .ToList();

            if (foundedBugs.Count() == 0)
            {
                return(RedirectToAction("Index", "Bug"));
            }

            return(View(foundedBugs));
        }
Exemplo n.º 6
0
        // GET: Search for bugs with state Fixed
        public ActionResult MyBugs(string AuthorId)
        {
            var db = new BugsTrackerDbContext();

            AuthorId = db.Users
                       .Where(u => u.UserName == this.User.Identity.Name)
                       .First()
                       .Id;

            var myBugs = db.Bugs
                         .Where(b => b.AuthorId == AuthorId)
                         .ToList();


            return(View(myBugs));
        }
Exemplo n.º 7
0
        //List Bugs
        public ActionResult List(int page = 1)
        {
            using (var database = new BugsTrackerDbContext())
            {
                var pageSize = 12;

                var bugs = database.Bugs
                           .OrderBy(b => b.Id)
                           .Skip((page - 1) * pageSize)
                           .Include(a => a.Author)
                           .ToList();

                ViewBag.CurrentPage = page;

                return(View(bugs));
            }
        }
Exemplo n.º 8
0
        public ActionResult AddComment(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var db = new BugsTrackerDbContext())
            {
                var bug = db.Bugs
                          .Where(b => b.Id == id)
                          .First();

                if (bug == null)
                {
                    return(HttpNotFound());
                }

                return(View());
            }
        }
Exemplo n.º 9
0
        //GET: Bug/Details
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var database = new BugsTrackerDbContext())
            {
                var bug = database.Bugs
                          .Where(a => a.Id == id)
                          .Include(a => a.Author)
                          .First();

                if (bug == null)
                {
                    return(HttpNotFound());
                }

                return(View(bug));
            }
        }
Exemplo n.º 10
0
        public ActionResult Edit(BugViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var database = new BugsTrackerDbContext())
                {
                    var bug = database.Bugs
                              .FirstOrDefault(b => b.Id == model.Id);

                    bug.Title       = model.Title;
                    bug.Description = model.Description;
                    bug.State       = model.State;
                    bug.RadioButton = model.RadioButton;

                    database.Entry(bug).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }
Exemplo n.º 11
0
        public ActionResult AddComment(Comment comment)
        {
            if (ModelState.IsValid)
            {
                using (var database = new BugsTrackerDbContext())
                {
                    var authorId = database.Users
                                   .Where(u => u.UserName == this.User.Identity.Name)
                                   .First()
                                   .Id;

                    comment.AuthorId  = authorId;
                    comment.DateAdded = DateTime.Now;

                    database.Comments.Add(comment);
                    database.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(View(comment));
        }
Exemplo n.º 12
0
        public ActionResult Report(Bug bug, HttpPostedFileBase attachment)
        {
            if (ModelState.IsValid)
            {
                using (var database = new BugsTrackerDbContext())
                {
                    var authorId = database.Users
                                   .Where(u => u.UserName == this.User.Identity.Name)
                                   .First()
                                   .Id;

                    bug.AuthorId  = authorId;
                    bug.DateAdded = DateTime.Now;
                    if (attachment != null)
                    {
                        var types = new[] { "image/jpg", "image/jpeg", "image/png" };
                        if (types.Contains(attachment.ContentType))
                        {
                            var attachmentPath = "/Data/Images/";
                            var attachmentName = attachment.FileName;
                            var uploadPath     = attachmentPath + attachmentName;
                            attachment.SaveAs(Server.MapPath(uploadPath));

                            bug.AttachmentURL = uploadPath;
                        }
                    }

                    database.Bugs.Add(bug);
                    database.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(View(bug));
        }