Exemple #1
0
        public async Task <ArticleDTO> UpdateArticleAsync(int articleId, UpdateArticleRequest updatedArticle)
        {
            var dbArticle = await articleRepository.GetArticleAsync(articleId);

            if (dbArticle == null)
            {
                return(null);
            }

            mapper.Map(updatedArticle, dbArticle);

            await articleRepository.UpdateArticleAsync(dbArticle);

            return(mapper.Map <ArticleDTO>(dbArticle));
        }
Exemple #2
0
        public async Task <ArticleDTO> CreateArticleAsync(UpdateArticleRequest createdArticle)
        {
            var existArticle = articleRepository.GetArticlesAsync().Result.FirstOrDefault(a => a.Title == createdArticle.Title);

            if (existArticle != null)
            {
                throw new ResourceHasConflictException($"Article with title {createdArticle.Title} exists.");
            }

            var dbArticle = mapper.Map <Article>(createdArticle);

            await articleRepository.CreateArticlesAsync(dbArticle);

            return(mapper.Map <ArticleDTO>(dbArticle));
        }