public async Task <IActionResult> AddArticle(ArticleModel article) { ArticleInfoModel articleInfo = article.ToArticleInfoModel(); ArticleContentModel articleContent = article.ToArticleContentModel(); await _articleService.AddArticleAsync(articleInfo, articleContent); return(Ok()); }
public async Task <IActionResult> Add(ArticleViewModel articleViewModel) { var isSuccess = await _articleService.AddArticleAsync(articleViewModel); if (!isSuccess) { return(this.BadRequestResult("添加失败!")); } return(Ok()); }
public async Task <ApiResult> AddArticleAsync([FromBody] AddArticleRequest request) { var user = GetUser(); if (user == null) { return(AuthorizeError()); } return(await _articleService.AddArticleAsync(request, user.UserId)); }
public async Task <IActionResult> OnGetNewArticleAsync(string articleType) { if (articleType.Equals("Markdown", StringComparison.InvariantCultureIgnoreCase)) { var newArticle = await articleService.AddArticleAsync(new Article() { ArticleType = ArticleType.MarkDown }); return(RedirectToPage($"/Articles/Edit", new { articleId = newArticle.Id })); } else { throw new NotImplementedException(); } }
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)); } }
public async Task <IActionResult> Create([FromBody] UpdateArticleRequest updateArticleIn) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = HttpContext.User.Claims.First().Value; updateArticleIn.UserId = userId; var article = await _articleService.AddArticleAsync(updateArticleIn); var location = $"api/[controller]/{article.Id}"; return(Created(location, article)); }
public async Task AddArticle_TestAsync() { var category = _categoryRep.GetAll().First(); var newArticle = await _articleService.AddArticleAsync(new Article() { ArticleType = ArticleType.HTML, CategoryId = category.Id, IsPublish = true, PostDate = DateTime.Now, PostImage = "123", Content = "11111", Title = "2222", }); newArticle.ArticleType.ShouldBe(ArticleType.HTML); newArticle.CheckAllPropertiesAreNotNullOrDefault(nameof(ArticleDto.ViewCount), nameof(ArticleDto.Tags)); _articleRep.Get(newArticle.Id).ArticleType.ShouldBe(ArticleType.HTML); }