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));
        }
Beispiel #2
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));
        }
        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));
        }