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