示例#1
0
        public CommentEvent MapEvent(Comments.Comment data, string eventName)
        {
            var dto = MapInternal <CommentEvent>(data);

            dto.Event = eventName;
            return(dto);
        }
示例#2
0
        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"))));
        }
示例#3
0
 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"
     });
 }
示例#4
0
        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}"));
        }
示例#5
0
 public Comment Map(Comments.Comment data)
 {
     return(MapInternal <Comment>(data));
 }