// POST: api/posts // *** Ingresa un nuevo comentario al post con <id> especificado public void PostComment(int id, [FromBody] Clases.comments value) { int mIdComment = (from c in Comments select c).Count(); Clases.comments mItem = new Clases.comments(); mItem.postId = id; mItem.id = mIdComment + 1; mItem.name = value.name; mItem.email = value.email; mItem.body = value.body; Comments.Add(mItem); }
// GET: api/posts/5 // *** Obtienen la información de un solo post con sus respectivos comentarios public Clases.postsComments Get(int id) { Posts = ObtienePosts(); Comments = ObtieneComments(); Clases.postsComments mPostsComments = new Clases.postsComments(); var q = from a in Posts where a.id == id orderby a.id select a; foreach (var item in q) { mPostsComments.post.userId = item.userId; mPostsComments.post.id = item.id; mPostsComments.post.title = item.title; mPostsComments.post.body = item.body; } var qq = from a in Comments where a.postId == id orderby a.postId, a.id select a; foreach (var item in qq) { Clases.comments mItem = new Clases.comments(); mItem.postId = item.postId; mItem.id = item.id; mItem.name = item.name; mItem.email = item.email; mItem.body = item.body; mPostsComments.comentarios.Add(mItem); } return(mPostsComments); }