Esempio n. 1
0
 public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.AuthorId = new SelectList(db.Users, "Id", "UserName", comment.AuthorId);
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "AuthorId", comment.TicketId);
     return View(comment);
 }
Esempio n. 2
0
        public ActionResult PostComment(CommentPostModel model)
        {
            if (!ModelState.IsValid)
            {
                var username = this.User.Identity.GetUserName();
                var userId = this.User.Identity.GetUserId();
                var ticket = this.Data.Tickets.All().FirstOrDefault(x => x.Id == model.TicketId);
                var comment = new Comment()
                {
                    AuthorId = userId,
                    Content = model.Content,
                    //TicketId = model.TicketId
                };

                ticket.Comments.Add(comment);
                this.Data.SaveChanges();

                var viewModel = new CommentViewModel { Author = username, Content = model.Content };
                return PartialView("_Comment", viewModel);
            }

            return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, ModelState.Values.First().ToString());
        }