public ActionResult EditComment(TicketCommentsModel editComment) { if (ModelState.IsValid) { // the Comments refers to the Model IdentityModels - public DbSet<Comment> Comments { get; set; }. if (!db.TicketCommentsData.Local.Any(c => c.Id == editComment.Id)) db.TicketCommentsData.Attach(editComment); db.Entry(editComment).Property(p => p.Comment).IsModified = true; editComment.UpdatedDate = System.DateTimeOffset.Now; db.SaveChanges(); } return RedirectToAction("Details", new { id = editComment.TicketId }); }
public ActionResult DeleteComment(TicketCommentsModel deleteComment) { if (ModelState.IsValid) { if (!db.TicketCommentsData.Local.Any(c => c.Id == deleteComment.Id)) db.TicketCommentsData.Attach(deleteComment); db.TicketCommentsData.Remove(deleteComment); db.SaveChanges(); } return RedirectToAction("Details", new { id = deleteComment.TicketId }); }
public ActionResult AddComment(TicketCommentsModel newComment) { if (ModelState.IsValid) { newComment.CreatedDate = System.DateTimeOffset.Now; newComment.UpdatedDate = null; newComment.UserId = User.Identity.GetUserId(); db.TicketCommentsData.Add(newComment); db.SaveChanges(); } return RedirectToAction("Details", new { id = newComment.TicketId }); }