public void DeleteComment(Comment comment)
 {
     using (var context = new Recipe2Context())
     {
         context.Entry(comment).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public Post SubmitPost(Post post)
 {
     using (var context = new Recipe2Context())
     {
         context.Posts.Attach(post);
         if (post.PostId == 0)
         {
             // this must be an insert
             context.Entry(post).State = EntityState.Added;
         }
         else
         {
             context.Entry(post).State = EntityState.Modified;
         }
         context.SaveChanges();
         return(post);
     }
 }
 public Comment SubmitComment(Comment comment)
 {
     using (var context = new Recipe2Context())
     {
         context.Comments.Attach(comment);
         if (comment.CommentId == 0)
         {
             // this is an insert
             context.Entry(comment).State = EntityState.Added;
         }
         else
         {
             // set single property to modified, which sets state of entity to modified, but
             // only updates the single property – not the entire entity
             context.Entry(comment).Property(x => x.CommentText).IsModified = true;
         }
         context.SaveChanges();
         return(comment);
     }
 }