Beispiel #1
0
        public async Task Consume(ConsumeContext <ArticleCreateRequestDto> context)
        {
            try
            {
                var article = _mapper.Map <Article>(context.Message.Article);

                var result = await _operationArticles.CreateArticle(article);

                var articleDto = _mapper.Map <ArticleDto>(result);

                await context.RespondAsync(new ArticleCreateResponseDto
                {
                    Article = articleDto
                });
            }
            catch (FailedToCreateArticleAppException e)
            {
                await context.RespondAsync(new FailedToCreateArticle
                {
                    CodeException    = e.CodeException,
                    MassageException = $"{e.Message}"
                });
            }
            catch (Exception e)
            {
                await context.RespondAsync(new FailedToCreateArticle
                {
                    MassageException = $"{e.Message}"
                });
            }
        }
        public async Task <IActionResult> CreateArticle(Article article)
        {
            try
            {
                var result = await _operationArticles.CreateArticle(article);

                return(Ok(result));
            }
            catch (FailedToCreateArticleAppException exception)
            {
                return(Ok(exception));
            }
        }