Exemplo n.º 1
0
        public async Task <CommentDto> AddAsync(CommentCreateDto dto)
        {
            if (string.IsNullOrEmpty(dto.Body))
            {
                throw new ArticleException(ArticleErrorCodes.CommentBodyCannotBeNull, "Comment Body field is mandatory.", dto);
            }

            if (dto.ArticleId == Guid.Empty)
            {
                throw new ArticleException(ArticleErrorCodes.CommentArticleIdConnotBeNull, "Comment Article Id field is mandatory.", dto);
            }

            var articleEntity = _articleRepository.GetByIdAsync(dto.ArticleId);

            if (articleEntity == null)
            {
                throw new ArticleException(ArticleErrorCodes.ArticleCouldNotBeFound, "Article could not be found.", null);
            }
            var entity = dto.Adapt <Domain.Comment>();

            entity = await _articleRepository.AddAsync(entity);

            return(entity.Adapt <CommentDto>());
        }