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()); } }
public virtual async Task <IActionResult> AddComment(Guid entityId, [FromBody] TmpComment comment) { return(await AddComment(entityId, null, comment)); }
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()); } }