Exemple #1
0
        public virtual async Task <IActionResult> EditComment(Guid commentId, [FromBody] TmpComment comment)
        {
            _logger.LogInformation($"Executing EditComment method, commentId={commentId}", comment);
            var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;

            try
            {
                await repository.EditForeignCommentAsync(commentId, comment.Comment, userId);

                await hubContext.Clients.User(userId).SendAsync("Success", "Comment has been edited");

                _logger.LogInformation($"Сomment deleted, userId={userId}");
                return(Ok());
            }
            catch (Exception ex)
            {
                await hubContext.Clients.User(userId).SendAsync("Error", "Could not edit a comment");

                _logger.LogError(ex, $"Editing own comment failed, userId={userId}");
                return(BadRequest());
            }
        }
Exemple #2
0
 public virtual async Task <IActionResult> AddComment(Guid entityId, [FromBody] TmpComment comment)
 {
     return(await AddComment(entityId, null, comment));
 }
Exemple #3
0
        public virtual async Task <IActionResult> AddComment(Guid entityId, Guid?baseCommentId, [FromBody] TmpComment comment)
        {
            _logger.LogInformation($"Executing AddComment method, entityId={entityId}, baseCommentId={baseCommentId}", comment);
            var userId = "";

            try
            {
                userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
                var newCommentId = await repository.AddCommentAsync(entityId, userId, baseCommentId, comment.Comment);

                await hubContext.Clients.User(userId).SendAsync("Success", "Comment has been added");

                _logger.LogInformation($"Comment added, userId={userId}");
                return(Ok(newCommentId));
            }
            catch (Exception ex)
            {
                if (userId != "")
                {
                    await hubContext.Clients.User(userId).SendAsync("Error", "Could not add a comment");
                }

                _logger.LogError(ex, $"Adding comment failed, userId={userId}");
                return(BadRequest());
            }
        }