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));
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> DeleteConfirmed(int id)
 {
     _repository.DeleteAuthor(id);
     return(RedirectToAction(nameof(Index)));
 }