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"; } }
public void ListViewComments_InsertItem() { var comment = new Server.Models.Comment(); comment.CreatedOn = DateTime.Now; comment.UserId = User.Identity.GetUserId(); comment.TopicId = int.Parse(Request.QueryString["id"]); TryUpdateModel(comment); if (ModelState.IsValid) { this.dbContext.Comments.Add(comment); this.dbContext.SaveChanges(); } Response.Redirect("~/ViewTopic?id=" + Request.QueryString["id"]); }