public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         var editedComment = this.Data.Comments.GetById(comment.Id);
         editedComment.Content = comment.Content;
         this.Data.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(comment);
 }
        public ActionResult Edit(Comment comment)
        {
            if (ModelState.IsValid)
            {
                var currentComment = db.Comments.FirstOrDefault(c => c.Id == comment.Id);
                currentComment.Content = comment.Content;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(comment);
        }
 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", "Title", comment.TicketId);
     return View(comment);
 }
        public ActionResult Create(Comment comment)
        {
            if (ModelState.IsValid)
            {
                db.Comments.Add(comment);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AuthorId = new SelectList(db.Users, "Id", "UserName", comment.AuthorId);
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", comment.TicketId);
            return View(comment);
        }
 public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         var commentTarget = this.Data.Commetns.GetById(comment.Id);
         commentTarget.Content = comment.Content;
         this.Data.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.PostedById = new SelectList(db.Users, "Id", "UserName", comment.PostedById);
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", comment.TicketId);
     return View(comment);
 }
 public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         var entity = db.Comments.Find(comment.Id);
         if (entity != null)
         {
             entity.Content = comment.Content;
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     ViewBag.AuthorId = new SelectList(db.Users, "Id", "UserName", comment.AuthorId);
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", comment.TicketId);
     return View(comment);
 }
        public ActionResult AddComment(CommentCreateModel commentModel, int ticketId)
        {
            var user = this.Data.Users.All().FirstOrDefault(u => u.UserName == this.User.Identity.Name);
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ModelState.IsValid)
            {
                var newComment = new Comment()
                {
                    Content = commentModel.Content,
                    Ticket = ticket,
                    User = user
                };

                this.Data.Comments.Add(newComment);
                this.Data.SaveChanges();

                return PartialView("_CommentPartial", new CommentDisplayModel() { Content = commentModel.Content, Username = this.User.Identity.Name });
            }
            else
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid comment");
            }
        }
        public ActionResult PostComment(CommentPostVIewModel comment)
        {
            if (ModelState.IsValid)
            {
                var ticket = Data.Tickets.All().FirstOrDefault(l => l.Id == comment.TicketId);
                var userId = User.Identity.GetUserId();
                var commentEntity = new Comment()
                {
                    AuthorId = userId,
                    TicketId = comment.TicketId,
                    Content = comment.Content
                };


                Data.Comments.Add(commentEntity);
                Data.SaveChanges();


                var comments = Data.Comments.All().Select(CommentViewModel.FromComment)
                    .Where(c => c.TicketId == commentEntity.TicketId).ToList();

                return PartialView("_AllComments", comments);
            }
            else
            {
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, ModelState.Values.First().ToString());
            }
        }
        public ActionResult Comment(CommentCreateViewModel comment)
        {
            if (User.Identity.IsAuthenticated && ModelState.IsValid)
            {
                var currentUserId = User.Identity.GetUserId();
                var newComment = new Comment()
                {
                    AuthorId = currentUserId,
                    Content = comment.Content,
                    TicketId = comment.Id
                };

                this.Data.Comments.Add(newComment);
                this.Data.SaveChanges();

                var currentUser = User.Identity.Name;

                return Content("<p><strong>" + currentUser + ": </strong>" + comment.Content + "</p>");
            }

            return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, ModelState.Values.First().ToString());
        }
        public ActionResult Comment(TicketCommentViewModel model)
        {
            if (Request.IsAjaxRequest())
            {
                if (!this.ModelState.IsValid) 
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                var username = this.User.Identity.GetUserName();
                var userId = this.User.Identity.GetUserId();

                var newComment = new Comment
                {
                    Text = model.CommentText,
                    AuthorId = userId,
                    TicketId = model.TicketId,
                };

                this.Data.Comments.Add(newComment);
                this.Data.SaveChanges();

                model.AuthorName = username;

                return PartialView("_CommentPartial", model);
            }

            return View();
        }