public void DeleteAuthorTest() { AddAuthorTest(); Assert.AreEqual(2, _dataLayer.GetAllAuthors().Count()); Author author = _dataLayer.GetAllAuthors().First(); _dataLayer.DeleteAuthor(author); Assert.AreEqual(1, _dataLayer.GetAllAuthors().Count()); Assert.AreEqual(null, _dataLayer.GetAuthor(author.Id)); }
public void DeleteAuthor() { using (var context = new LibraryContext(options)) { var service = new LibraryRepository(context); var author = new Author() { Id = 3 }; Assert.IsTrue(context.Authors.Any(a => a.Id == 3)); service.DeleteAuthor(author); context.SaveChanges(); Assert.IsFalse(context.Authors.Any(a => a.Id == 3)); } }
public IActionResult DeleteAuthor(Guid id) { var authorRepository = LibraryRepository.GetAuthor(id); if (authorRepository == null) { return(NotFound()); } LibraryRepository.DeleteAuthor(authorRepository); if (LibraryRepository.NotSave()) { throw new Exception($"Deleting author {id} failed on save."); } return(NoContent()); }
public async Task <IActionResult> DeleteConfirmed(int id) { _repository.DeleteAuthor(id); return(RedirectToAction(nameof(Index))); }