public ActionResult AddComment(int? id, string commentText) { // í gagnagrunn fyrir if (!User.Identity.IsAuthenticated) // ákveðið TranslationID { Response.StatusCode = 404; return Json(null, JsonRequestBehavior.DenyGet); // Deny ef user er ekki innskráður } Comment comment = new Comment(); // Byr til tilvik af comment og UpdateModel(comment); // og gefur thvi rétt gildi, comment.CommentText = commentText; // addar svo í gagnagrunn comment.TranslationID = id.Value; // og skilar json comment.UserName = User.Identity.Name; comment.commentDate = DateTime.Now; CommentRepo.AddComment(comment); return Json(comment, JsonRequestBehavior.AllowGet); }
public void AddComment(Comment c) { m_db.Comments.Add(c); m_db.SaveChanges(); }