Example #1
0
        public async Task <ArticleModel> GetArticleByIdAsync(int articleId)
        {
            try
            {
                Article entity = await this.repo.GetArticleByIdAsync(articleId).ConfigureAwait(false);

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

                ArticleModel model = new ArticleModel();
                model.ToModel(entity);

                return(model);
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        public async Task <ArticleModel> UpdateArticleAsync(ArticleModel model)
        {
            model = model ?? throw new ArgumentNullException(nameof(model));

            try
            {
                Article entity = await this.repo.UpdateArticleAsync(model.ToEntity()).ConfigureAwait(false);

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

                ArticleModel updatedModel = new ArticleModel();
                updatedModel.ToModel(entity);

                return(updatedModel);
            }
            catch
            {
                throw;
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fileFolderPath">Need folders {fileFolderPath}/Files/ArticleFiles</param>
        /// <returns></returns>
        public async Task <ArticleModel> CreateArticleAsync(ArticleModel model, string fileFolderPath)
        {
            model          = model ?? throw new ArgumentNullException(nameof(model));
            fileFolderPath = fileFolderPath ?? throw new ArgumentNullException(nameof(fileFolderPath));

            try
            {
                Article entity = await this.repo.CreateArticleAsync(model.ToEntity(), fileFolderPath).ConfigureAwait(false);

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

                ArticleModel addedModel = new ArticleModel();
                addedModel.ToModel(entity);

                return(addedModel);
            }
            catch
            {
                throw;
            }
        }
        public async Task <ArticleModel> GetArticle(string articleId)
        {
            var article = await articleService.GetArticle(articleId);

            return(ArticleModel.ToModel(article));
        }