Exemplo n.º 1
0
        public virtual async Task<CommentModel> UpdateAsync(CommentEditDto dto)
        {
            var comment = await _commentsRepository.GetAsync(dto.Id);
            var commentLinkPreview = _commentLinkPreviewService.GetCommentsLinkPreviewAsync(comment.Id);

            comment.ModifyDate = DateTime.UtcNow;
            comment.Text = dto.Text;

            await _commentsRepository.UpdateAsync(comment);

            if (dto.LinkPreviewId.HasValue)
            {
                if (commentLinkPreview?.Id != dto.LinkPreviewId)
                {
                    await _commentLinkPreviewService.UpdateLinkPreviewAsync(dto.Id, dto.LinkPreviewId.Value);
                }
            }
            else
            {
                await _commentLinkPreviewService.RemovePreviewRelationsAsync(dto.Id);
            }

            return comment.Map<CommentModel>();
        }