public Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "") { var newReaction = new ArticleReaction { ArticleSlug = articleSlug, TimestampId = (new ArticleReactionTimestampId(timestamp, replyingTo)).ToString(), Content = content, AuthorId = userId, AuthorName = userName, ReactionType = articleReactionType }; _GetReactionsDictionaryForArticle(articleSlug).Add(newReaction); return(Task.FromResult(newReaction.ReactionId)); }
public async Task <IEnumerable <ArticleReaction> > GetArticleReactions(string articleSlug, string sinceTimestamp = "", int pageSize = 50, bool latest = false) { var listToReturn = new SortedSet <ArticleReaction>(); var currentComment = new ArticleReaction(); void _addIfMatchesCriteria() { if (currentComment.ArticleSlug == articleSlug) { if (string.IsNullOrWhiteSpace(sinceTimestamp) || currentComment.TimestampAsString.CompareTo(sinceTimestamp) > 0) { listToReturn.Add(currentComment); } } } using (var reader = File.OpenText(Path.Combine(RootFolder, "comments.txt"))) { bool readingContent = false; var lineRead = await reader.ReadLineAsync(); while (lineRead != null) { if (lineRead.StartsWith(COMMENT_SEPARATOR)) { _addIfMatchesCriteria(); currentComment = new ArticleReaction(); readingContent = false; } else { if (readingContent) { currentComment.Content += Environment.NewLine + lineRead; } else { currentComment.ArticleSlug = lineRead; currentComment.TimestampId = await reader.ReadLineAsync(); currentComment.AuthorId = await reader.ReadLineAsync(); currentComment.AuthorName = await reader.ReadLineAsync(); currentComment.ReactionType = (ArticleReactionType)Enum.Parse(typeof(ArticleReactionType), await reader.ReadLineAsync()); currentComment.EditState = (ArticleReactionEditState)Enum.Parse(typeof(ArticleReactionEditState), await reader.ReadLineAsync()); currentComment.Content = await reader.ReadLineAsync(); readingContent = true; } } lineRead = await reader.ReadLineAsync(); } } _addIfMatchesCriteria(); if (latest) { return(listToReturn.Reverse().Take(pageSize)); } else { return(listToReturn.Take(pageSize)); } }