protected virtual void UpsertIntoCollection(RedditComment comment) { var collection = GetMongoCommentCollection(); collection.ReplaceOne( filter: new BsonDocument("_id", comment.Id), options: new ReplaceOptions { IsUpsert = true }, replacement: comment.ToBsonDocument()); }
public IEnumerable <RedditComment> GetRecentComments(int numComments) { List <RedditComment> output = new List <RedditComment>(); using (var httpResponse = httpClient.GetAsync(GetRecentCommentsRequestUrl(numComments)).Result) { HttpContent content = httpResponse.Content; if (httpResponse.StatusCode != HttpStatusCode.OK || content == null) { return(output); } RedditCommentQueryResponse parsedContent = JsonConvert.DeserializeObject <RedditCommentQueryResponse>(content.ReadAsStringAsync().Result); foreach (Comment redditComment in parsedContent?.data?.children) { RedditComment toAdd = new RedditComment(redditComment.data); output.Add(toAdd); } } return(output); }