public ActionResult AddAuthor(string name) { AuthorsService service = new AuthorsService(); int id = service.AddAuthor(name); return(RedirectToAction("AuthorsSelectList", new { selectedId = id })); }
public async Task AddAuthorShouldAddAuthor() { var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new BookTubeContext(optionsBuilder.Options); var service = new AuthorsService(dbContext); var author = new Author { Id = 1, Name = "Ivan Vazov", Bio = "Born in Sopot, Bulgaria" }; await service.AddAuthor(author.Name, author.Bio); var authorFromDb = dbContext.Authors.Select(x => x.Name).First(); Assert.Equal(authorFromDb, author.Name); }
public IActionResult AddAuthor([FromBody] AuthorVM author) { _authorsService.AddAuthor(author); return(Ok()); }