public async Task <IActionResult> Post([FromBody] BlogArticleAddViewModel blogArticleAddViewModel) { if (blogArticleAddViewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new MyUnprocessableEntityObjectResult(ModelState)); } var blog = _mapper.Map <BlogArticleAddViewModel, BlogArticle>(blogArticleAddViewModel); blog.bsubmitter = "laozhang"; blog.bCreateTime = DateTime.Now; blog.bUpdateTime = DateTime.Now; var blogId = await _blogArticleRepository.Add(blog); var resultResource = _mapper.Map <BlogArticle, BlogArticleViewModel>(blog); return(Ok(resultResource)); }
public async void Add_Blog_Test() { BlogArticle blogArticle = new BlogArticle() { bCreateTime = DateTime.Now, bUpdateTime = DateTime.Now, btitle = "xuint test title", bcontent = "xuint test content", bsubmitter = "xuint: test repositoryBase add blog", }; var BId = await baseRepository.Add(blogArticle); Assert.True(BId > 0); }
public void Add(AddWorkCommand work) { if (string.IsNullOrEmpty(work.Title) || string.IsNullOrEmpty(work.Content)) { throw new LogicException(LogicExceptionMessage.LoginNameOrPasswordIsNull); } var info = new BlogArticle { Title = work.Title, Category = work.Category, Content = work.Content, CreateUser = LoginUserSection.CurrentUser.LoginName, CreateDate = _currentTimeProvider.CurrentTime(), Status = Enums.Status.Exist }; _articleRepository.Add(info); }