public CommentEvent MapEvent(Comments.Comment data, string eventName) { var dto = MapInternal <CommentEvent>(data); dto.Event = eventName; return(dto); }
private static string UniqueHash(Comments.Comment comment) { var id = string.IsNullOrWhiteSpace(comment.Email) ? comment.Name : comment.Email; var hash = hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(id.ToLower())); return(string.Concat(hash.Select(b => b.ToString("x2")))); }
private TComment MapInternal <TComment>(Comments.Comment data) where TComment : Comment, new() { return(new TComment { Id = data.RowKey, Key = HttpUtility.UrlDecode(data.PartitionKey), Name = data.Name, Approved = data.Approved, Content = Markdown.ToHtml(data.Content, _markdownOutputPipeline), Markdown = data.Content, Email = data.Email ?? "", Posted = data.Posted, Avatar = $"https://www.gravatar.com/avatar/{UniqueHash(data)}?d=identicon" }); }
public async Task <IActionResult> Comment(int id, string text, string vote) { // Change vote int _vote = -1; if (Int32.TryParse(vote, out _vote)) { await db.ChangeVoteAsync(id, (int)TempData.Peek("id"), _vote); } // Add comment var userId = (int)TempData.Peek("id"); var comment = new Comments.Comment() { UserId = userId, ProductId = id, Text = text }; if (!await db.IsCommentedAsync((int)TempData.Peek("id"), id)) { await db.AddCommentAsync(comment); } return(RedirectToAction($"Get/{id}")); }
public Comment Map(Comments.Comment data) { return(MapInternal <Comment>(data)); }