public void SaveComment(Comment comment)
        {
            if (context.Comments.Count(b => b.CommentId == comment.CommentId) != 0)
            {
                context.Comments.Single(b => b.CommentId == comment.CommentId).Update(comment);
            }
            else
            {
                context.Comments.Add(comment);
            }

            context.SaveChanges();
        }
 public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         repository.SaveComment(comment);
         TempData["message"] = string.Format("{0} has been saved");
         return View(comment);
     }
     else
     {
         // there is something wrong with the data values
         return View(comment);
     }
 }
 public void DeleteComment(Comment comment)
 {
     context.Comments.Remove(comment);
     context.SaveChanges();
 }
Example #4
0
 /// <summary>
 /// Updates the specified new comment.
 /// </summary>
 /// <param name="newComment">The new comment.</param>
 public void Update(Comment newComment)
 {
     this.Modified = DateTime.Now;
     this.Username = newComment.Username;
     this.Content = newComment.Content;
 }