public ActionResult DeleteConfirmed(int id) { Author author = Mapper.Map <Author>(_authorRepo.Read(id)); _authorRepo.Delete(Mapper.Map <AuthorBusiness>(author)); return(RedirectToAction("Index")); }
public async Task DeleteAuthor_DeletesCorrectAuthor() { // Arrange var databaseName = Guid.NewGuid().ToString(); var context = BuildContext(databaseName); context.Authors.Add(CreateFakeAuthor("John", "Testman1")); context.Authors.Add(CreateFakeAuthor("John", "Testman2")); context.SaveChanges(); var context2 = BuildContext(databaseName); var delAuthor = new Author() { Id = 1, LastName = "Testman1" }; // Act var repo = new AuthorRepository(context2); var wasUpdated = await repo.Delete(delAuthor); // Assert Assert.True(wasUpdated); var author = context2.Authors.First(); Assert.Equal("Testman2", author.LastName); }
public void Delete_WhenCalled_ShouldDeleteAuthorFromDatabase() { // Arrange var author = new Author { Id = new Guid(), Books = new List <Book>(), DateOfBirth = new DateTimeOffset(), FirstName = "John", LastName = "Smith", Genre = "Adventure" }; var numberOfAuthorsBeforeChanges = _context.Authors.Count(); _context.Authors.Add(author); _context.SaveChanges(); // Act _authorRepository.Delete(author.Id); _unitOfWork.Complete(); // Assert var result = _context.Authors.ToList(); Assert.That(result, Has.Count.EqualTo(numberOfAuthorsBeforeChanges)); }
public ActionResult DeleteConfirmed(int id) { Author author = MappingWeb.ConvertToWebEntity(_authorRepo.Read(id)); _authorRepo.Delete(MappingWeb.ConvertToBusinessEntity(author)); return(RedirectToAction("Index")); }
private void Btn_cancel_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtbx_firstName.Text)) { this.Close(); } else { var author = _authorRepository.GetAll().Where(x => x.Person.FirstName.Equals(txtbx_firstName.Text) && x.Person.LastName.Equals(txtbx_lastName.Text)).FirstOrDefault(); if (author != null) { var personId = author.Person.PersonID; var book = _bookRepository.GetAll().Where(x => x.AuthorID == author.ID); var cardholder = _cardholderRepository.GetAll() .Where(x => x.Person.PersonID == personId).FirstOrDefault(); if (book == null) { _authorRepository.Delete(author.ID); } if (cardholder == null) { _personRepository.Delete(personId); } } } this.Close(); }
public void Cannot_Delete_NonExists_Author_From_DataSource() { // Arrange var author = new Author { AccountName = "glog", Description = "testing user", IsActivated = true }; AuthorRepository.Add(author); var author2 = new Author { Id = Guid.NewGuid(), AccountName = "glog2", Description = "testing user", IsActivated = true }; // Act var result = AuthorRepository.Delete(author2); // Assert Assert.False(result); Assert.False(AuthorRepository.ProcessMessage.Success); Assert.Single(AuthorRepository.ProcessMessage.MessageList); }
private void Remove() { Author authorToDelete = Choose("Which author would you like to remove?"); if (authorToDelete != null) { _authorRepository.Delete(authorToDelete.Id); } }
public void DeleteNonExistenceAuthor() { AuthorRepository repository = new AuthorRepository(); Author author = new Author("sada", "sadasd", "sdaasd", new DateTime(1990, 2, 3)); repository.Add(author); repository.Delete(author.Id); Assert.IsTrue(repository.IsEmpty()); }
public void DeleteAuthor() { AuthorRepository repository = new AuthorRepository(); repository.Add(AUTHOR); repository.Delete(AUTHOR.Id); Assert.IsTrue(repository.IsEmpty()); }
public ActionResult Delete(int id, AuthorViewModel author) { try { authorRepo.Delete(id); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
private void Remove() { Author authorToDelete = Choose("Which author would you like to remove?"); if (authorToDelete != null) { _authorRepository.Delete(authorToDelete.Id); Console.WriteLine($"{authorToDelete.FullName} deleted!"); } }
public async void CreateReadDelete() { var testAuthor = new AuthorDto { Author = DateTime.Now.Ticks.ToString() }; var createTest = await Sut.Create(new[] { testAuthor }); Assert.Equal(1, createTest); var test = await Sut.Read(new[] { testAuthor.Author }); Assert.NotNull(test); Assert.IsAssignableFrom <IEnumerable <AuthorDto> >(test); var deleteTest = await Sut.Delete(new[] { test.FirstOrDefault().Id ?? 0 }); Assert.Equal(1, deleteTest); }
public IHttpActionResult DeleteAuthor(int id) { Author author = authorRepository.GetById(id); if (author == null) { return(NotFound()); } authorRepository.Delete(author); return(Ok(author)); }
private void Remove() { Author authorToDelete = Choose("Which author would you like to remove?"); if (authorToDelete != null) { _authorRepository.Delete(authorToDelete.Id); Console.WriteLine("Author has been removed."); } Console.WriteLine(); }
public ActionResult Delete(int id, Article article) { try { authorRepository.Delete(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public void Delete(int id) { _repository.Delete(id); //get related books etc. var relatedObjects = _bookAuthorRepository.GetAll().Where(x => x.AuthorId == id); //delete related books etc. foreach (var r in relatedObjects) { _bookAuthorRepository.Delete(r); } }
public void Should_Delete_An_Entity() { var repository = new AuthorRepository(); var author = repository.Insert(new Author() { FirstName = "Bruce", LastName = "Wayne" }); repository.Delete(author.Id); author = repository.GetById(author.Id); Assert.IsNull(author); }
public async void DeleteAuthorTest() { AuthorRepository authorRepository = new AuthorRepository(_dataContext); var author = await authorRepository.GetAuthorByNameAsync("Teste Atualizado"); authorRepository.Delete(author); await authorRepository.SaveChangesAsync(); var result = await authorRepository.ExistAuthorByName(author.Name); Assert.False(result); }
public void crud_process_succeeds() { var entityId = 797; var entity = new Author { Id = entityId , AuthorCode = "ABC-54321" , FirstName = "Unit" , LastName = "Test" , PhoneNumber = "3607259465" , Address = "549 SW Olympic Ave" , City = "Lacey" , State = "WA" , ZipCode = "98503" , Contract = false }; var savedEntity = _repository.Add(entity); var updatedEntity = _repository.GetById(entityId); using (new AssertionScope()) { savedEntity.Should().NotBeNull(); savedEntity.Id.Should().Be(entityId); savedEntity.FirstName.Should().Be("Unit"); savedEntity.PhoneNumber.Should().Be("3607259465"); savedEntity.Contract.Should().BeFalse(); savedEntity.AuthorCode.Should().Be("ABC-54321"); updatedEntity.Should().NotBeNull(); updatedEntity.Id.Should().Be(entityId); updatedEntity.FirstName.Should().Be("Unit"); updatedEntity.PhoneNumber.Should().Be("3607259465"); updatedEntity.Contract.Should().BeFalse(); updatedEntity.AuthorCode.Should().Be("ABC-54321"); updatedEntity.FirstName = "UnitUnit"; updatedEntity.LastName = "TestTest"; updatedEntity.Contract = true; _repository.Update(updatedEntity); updatedEntity = _repository.GetById(entityId); updatedEntity.FirstName.Should().Be("UnitUnit"); updatedEntity.LastName.Should().Be("TestTest"); updatedEntity.Contract.Should().BeTrue(); _repository.Delete(updatedEntity); _repository.GetById(entityId).Should().BeNull(); } }
public void Cannot_Delete_Author_With_Note_Associated() { // Arrange var render = new NoteRender { Name = "DefaultRender", Namespace = "NameSpace", IsDefault = true, Description = "Description" }; var savedRender = RenderRepository.Add(render); var catalog = new NoteCatalog { Name = "DefaultCatalog", Render = savedRender, Schema = "testScheme", IsDefault = false, Description = "Description" }; var savedCatalog = CatalogRepository.Add(catalog); var author = new Author { AccountName = "glog", Description = "testing user", IsActivated = true }; var savedUser = AuthorRepository.Add(author); var note = new HmmNote { Subject = string.Empty, Content = string.Empty, CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now, Author = savedUser, Catalog = savedCatalog }; NoteRepository.Add(note); // Act var result = AuthorRepository.Delete(author); // Assert Assert.False(result, "Error: deleted user with note"); Assert.False(AuthorRepository.ProcessMessage.Success); Assert.Single(AuthorRepository.ProcessMessage.MessageList); }
private void btnEliminar_Click(object sender, EventArgs e) { Author author = new Author() { au_fname = "Juan Manuel", au_lname = "Perez", au_id = "22-1242-323", phone = "415-333-2117", contract = true }; int result = AuthorRepository.Delete(author); MostrarAuthors(); }
public ActionResult Delete(int id, FormCollection collection) { try { using (var repo = new AuthorRepository()) { repo.Delete(id); } return(RedirectToAction("Index")); } catch { return(View()); } }
private void Remove() { Author authorToDelete = Choose("Which author would you like to remove?"); if (authorToDelete != null) { try { _authorRepository.Delete(authorToDelete.Id); } catch (Exception ex) { Console.WriteLine("Invalid Selection. This author has corresponding posts that must be deleted first."); } } }
public void Dispose() { if (_dbContext is DbContext context) { context.Reset(); } var systems = LookupRepo.GetEntities <Subsystem>().ToList(); foreach (var sys in systems) { SubsystemRepository.Delete(sys); } var notes = LookupRepo.GetEntities <HmmNote>().ToList(); foreach (var note in notes) { NoteRepository.Delete(note); } var catalogs = LookupRepo.GetEntities <NoteCatalog>().ToList(); foreach (var catalog in catalogs) { CatalogRepository.Delete(catalog); } var renders = LookupRepo.GetEntities <NoteRender>().ToList(); foreach (var render in renders) { RenderRepository.Delete(render); } var authors = LookupRepo.GetEntities <Author>().ToList(); foreach (var author in authors) { AuthorRepository.Delete(author); } if (_dbContext is DbContext newContext) { newContext.Reset(); } GC.SuppressFinalize(this); }
public void Can_Delete_Author_From_DataSource() { // Arrange var author = new Author { AccountName = "glog", Description = "testing user", IsActivated = true }; var savedAuthor = AuthorRepository.Add(author); // Act var result = AuthorRepository.Delete(savedAuthor); // Assert Assert.True(result); }
public IActionResult Delete(int id) { AuthorRepository r = new AuthorRepository(); if (r.Delete(id)) { return(Ok("Author data successfully removed")); } else { var response = new ContentResult() { StatusCode = StatusCodes.Status409Conflict, Content = "Removing failed... No author data for id = " + id }; return(response); } }
//public ActionResult Delete( BookModel book) //{ // BooksRepository r = new BooksRepository(); // for (int i = 0; i <= listaCarti.Count - 1; i++) // { // if (book.Id == listaCarti[i].Id) // { // listaCarti.Remove(listaCarti[i]); // } // } // return View("Succes2"); //} public ActionResult Delete(int id) { //var b1 = listaCarti.Find(x => x.Id == id); //listaCarti.Remove(b1); AuthorRepository r = new AuthorRepository(); r.Delete(id); List <Authors> myAutori = r.GetAll(); // foreach (BookModel book in listaCarti) // { // if (book.Id == id) // { // listaCarti.RemoveAt(id); // return View("List", listaCarti); // } // } return(View("ListaAutori", myAutori)); }
public /*async*/ void Delete(int id) { /*await*/ authorsRepository.Delete(id); }
public async Task Delete(int id) { await _authorRepository.Delete(id); }
public void DeleteAuthor(int id) { _authorRepository.Delete(id); }
public void Delete(AuthorViewModel authorViewModel) { _authorRepository.Delete(authorViewModel.Id); }