Пример #1
0
        public async Task UpdateAsync(Guid commentId, SaveCommentModel saveCommentModel)
        {
            var updateCommentModel = new UpdateCommentModel
            {
                Id      = commentId,
                Content = saveCommentModel.Content
            };

            await _commentManager.UpdateCommentAsync(updateCommentModel);
        }
        ///<inheritdoc/>
        public async Task SynchronizeForUpdatingCommentsAsync()
        {
            _logger.LogInformation(Application.Resources.CommentSynchronizationService.StartSynchronizationForUpdationComment);

            var cloudComments = await _cloudManager.GetComments().ToListAsync();

            var applicationComments = (await _commentManager.GetCommentsWithoutTrackingAsync()).ToList();

            foreach (var appComment in applicationComments)
            {
                var isUpdated = false;

                var applicationPost = await _postManager.GetPostWithoutTrackingAsync(appComment.PostId);

                var cloudComment = cloudComments.FirstOrDefault(comment => comment.Id == appComment.CloudId);

                if (applicationPost.CloudId != cloudComment.PostId)
                {
                    var postId = (await _postManager.GetPostWithoutTrackingByCloudIdAsync(cloudComment.Id)).Id;

                    appComment.PostId = postId; // !!!
                    isUpdated         = true;
                }

                if (appComment.Name != cloudComment.Name)
                {
                    appComment.Name = cloudComment.Name;
                    isUpdated       = true;
                }

                if (appComment.Email != cloudComment.Email)
                {
                    appComment.Email = cloudComment.Email;
                    isUpdated        = true;
                }

                if (appComment.Body != cloudComment.Body)
                {
                    appComment.Body = cloudComment.Body;
                    isUpdated       = true;
                }

                if (isUpdated)
                {
                    await _commentManager.UpdateCommentAsync(appComment);
                }
            }

            _logger.LogInformation(Application.Resources.CommentSynchronizationService.EndSynchronizationForUpdationComment);
        }