///<inheritdoc/> public async Task SynchronizeForAddingCommentsAsync() { _logger.LogInformation(Application.Resources.CommentSynchronizationService.StartSynchronizationForUpdationComment); var cloudComments = await _cloudManager.GetComments().ToListAsync(); var applicationComments = (await _commentManager.GetCommentsWithoutTrackingAsync()).ToList(); var cloudCommentsIds = cloudComments.Select(c => c.Id).ToList(); var applicationCommentsIds = applicationComments.Select(c => c.CloudId).ToList(); var idsForSync = cloudCommentsIds.Except(applicationCommentsIds); var commentsForSync = cloudComments.Join(idsForSync, cloudComment => cloudComment.Id, newId => newId, (cloudComment, newId) => cloudComment); if (commentsForSync.Any()) { foreach (var comment in commentsForSync) { var applicationPosts = await _postManager.GetPostsWithoutTrackingAsync(); var post = applicationPosts.FirstOrDefault(post => post.CloudId == comment.PostId); if (post != null) { var commentDto = new CommentDto { CloudId = comment.Id, PostId = post.Id, Email = comment.Email, Name = comment.Name }; await _commentManager.CreateCommentAsync(commentDto); } else { _logger.LogError(ErrorMessages.CommentSyncService_AddingCommentError, comment.PostId); } } } _logger.LogInformation(Application.Resources.CommentSynchronizationService.EndSynchronizationForUpdationComment); }