Example #1
0
        public async Task <IActionResult> Create([FromBody] AddArticleDto dto)
        {
            var model   = this.mapper.Map <AddArticleModel>(dto);
            var created = await this.articleService.AddAsync <ArticleDto>(model);

            return(this.Created($"/api/article/{created.Id}", created));
        }
Example #2
0
        public ArticleDto AddWithTags(AddArticleDto dto, IList <AddTagDto> tags)
        {
            var entity = _articleDomainService.Add(Mapper.Map <Article>(dto));

            _articleTagDomainService.AddTags(entity.Id, Mapper.Map <IList <Tag> >(tags));
            return(Mapper.Map <ArticleDto>(entity));
        }
Example #3
0
        public ArticleDto Update(int id, [FromBody] AddArticleDto dto)
        {
            var articleDto = dto.MapTo <ArticleDto>();

            articleDto.Id = id;
            return(_articleAppService.Update(articleDto));
        }
Example #4
0
        public IResult CreateArticle(AddArticleDto addArticleDto)
        {
            var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckArticleCategoryExist(addArticleDto.ArticleCategoryId));


            if (errorResult != null)
            {
                return(errorResult);
            }


            var user = _authService.GetAuthenticatedUser().Result.Data;


            var article = new Article()
            {
                Title             = addArticleDto.Title,
                Content           = addArticleDto.Content,
                UserId            = user.Id,
                ArticleCategoryId = addArticleDto.ArticleCategoryId
            };

            user.UserHistories.Add(new UserHistory()
            {
                ArticleCategoryId = addArticleDto.ArticleCategoryId
            });
            _uow.Articles.Add(article); //
            _uow.Commit();              //

            return(new SuccessResult(Message.ArticleCreated));
        }
Example #5
0
        public async Task <JsonResult> Add(AddArticleDto model)
        {
            var result = await _articleAppService.Add(model);

            OutputModel outputModel = new OutputModel();

            outputModel.Data = result;
            return(new JsonResult(outputModel));
        }
Example #6
0
        public async Task <bool> AddArticle(AddArticleDto article, string userId)
        {
            var articleToAdd = new Article
            {
                Title   = article.Title,
                Content = article.Content,
                UserId  = userId
            };

            this.dbContext.Articles.Add(articleToAdd);
            return(await this.dbContext.SaveChangesAsync() > 0);
        }
Example #7
0
        public async Task <IActionResult> AddArticle([FromBody] AddArticleDto article)
        {
            var userId = this.usersManager.GetUserId(this.User);

            var success = await this.articlesService.AddArticle(article, userId);

            if (success)
            {
                return(Ok());
            }

            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
Example #8
0
        public IActionResult CreateArticle(AddArticleDto addArticleDto)
        {
            var result = _articleService.CreateArticle(addArticleDto);

            if (result.ResultType == ResultType.UnAuthorized)
            {
                return(Unauthorized());
            }

            if (result.ResultType == ResultType.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="addArticleDto">添加文章对象</param>
        /// <returns></returns>
        public async Task <ShowArticleDto> AddArticleAsync(AddArticleDto addArticleDto)
        {
            ArticleType articleType = await _articleTypeRepository.GetByIdAsync(addArticleDto.ArticleTypeId);

            Guard.Against.NullArticleType(addArticleDto.ArticleTypeId, articleType);
            var article = _mapper.Map <Article>(addArticleDto);

            article.SetArticleType(articleType);
            //返回展示模型
            if (await _articleRepository.AddAsync(article))
            {
                var showArticle = _mapper.Map <ShowArticleDto>(article);
                return(showArticle);
            }
            _logger.LogError($"文章添加失败。失败数据:{JsonConvert.SerializeObject(article)}");
            return(null);
        }
Example #10
0
        public ArticleDto Add(AddArticleDto dto)
        {
            var entity = _articleDomainService.Add(Mapper.Map <Article>(dto));

            return(Mapper.Map <ArticleDto>(entity));
        }
Example #11
0
 public async Task <Result> Add(AddArticleDto dto)
 {
     return(await _articleService.Add(_mapper.Map <Article>(dto)));
 }
Example #12
0
        public IActionResult Add(AddArticleDto dto)
        {
            var list = _articleAppService.Add(dto);

            return(RedirectToAction("Index"));
        }
Example #13
0
 public ArticleDto Add([FromBody] AddArticleDto dto)
 {
     return(_articleAppService.Add(dto));
 }
        public async Task <ActionResult <ResponseResult <ShowArticleDto> > > AddArticleAsync([FromBody] AddArticleDto addArticleDto)
        {
            var a = DateTime.Now;

            try
            {
                var addArticle = await _articleService.AddArticleAsync(addArticleDto);

                return(new ResponseResult <ShowArticleDto>(1, "添加成功", addArticle));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, ex.Message);
                return(new ResponseResult <ShowArticleDto>(0, ex.Message, null));
            }
        }