public ResultViewModel Post([FromBody] EditorArticleViewModel model) { if (string.IsNullOrEmpty(model.Title) || string.IsNullOrEmpty(model.Content)) { return(new ResultViewModel { Success = false, Message = "It was not possible to create an article." }); } var articleAlreadySaved = _articleRepository.GetByTitle(model.Title); if (articleAlreadySaved != null) { return(new ResultViewModel { Success = false, Message = "This title has already taken.", Data = null }); } var article = new Article(model.Title, model.Content, DateTime.Now, DateTime.Now); _articleRepository.save(article); return(new ResultViewModel { Success = true, Message = "Article create with success.", Data = article }); }
public ResultViewModel Put([FromBody] EditorArticleViewModel model) { if (string.IsNullOrEmpty(model.Title) || string.IsNullOrEmpty(model.Content)) { return(new ResultViewModel { Success = false, Message = "It was not possible to update an article.", Data = model }); } var article = _articleRepository.GetById(model.Id); article.Title = model.Title; article.Content = model.Content; article.UpdatedAt = DateTime.Now; _articleRepository.update(article); return(new ResultViewModel { Success = true, Message = "Article updated with success.", Data = article }); }
public ArticlesControllerTest() { var fake = new Faker(); _articleModel = new EditorArticleViewModel { Id = fake.Random.Number(1, 1000), Title = fake.Lorem.Sentence(), Content = fake.Lorem.Paragraph() }; _articleRepositoryMock = new Mock <IArticleRepository>(); _articlesController = new ArticlesController(_articleRepositoryMock.Object); }