public List <PostComment> GetComments() { List <PostComment> ls = new List <PostComment>(); var list = db.Comments.ToList(); foreach (var item in list) { var posted = new PostComment() { Id = item.id, comment1 = item.comment1, postId = item.postId, UserId = item.UserId }; ls.Add(posted); } return(ls); }
public bool PostComment(PostComment postComment) { try { var comment = new Comment() { comment1 = postComment.comment1, postId = postComment.postId, UserId = postComment.UserId }; db.Comments.Add(comment); db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; } }