public string deleteComment(int CommentID) { try { using (var ctx = new CommentContext()) { Comment oldComment = ctx.Comments.Find(CommentID); if (oldComment != null) { ctx.Comments.Remove(oldComment); ctx.SaveChanges(); } } return "ok"; } catch (Exception) { return "fail"; } }
public string updateComment(int CommentID, string CommentText) { try { using (var ctx = new CommentContext()) { Comment oldComment = ctx.Comments.Find(CommentID); if (oldComment != null) { oldComment.CommentText = CommentText; ctx.SaveChanges(); } } return "ok"; } catch (Exception) { return "fail"; } }
public string createComment(string Comment, int PostID) { try { using (var ctx = new CommentContext()) { Comment comment = new Comment() { CommentText = Comment, PostID = PostID, CommentDate = new DateTime() }; ctx.Comments.Add(comment); ctx.SaveChanges(); } return "ok"; } catch (Exception) { return "fail"; } }