public ActionResult Delete(int id) { AnimalRepository animalRep = new AnimalRepository(); animalRep.Delete(id); return(RedirectToAction("List")); }
public void Delete(long id) { Animal animal = animalRepository.GetById(id); if (animal == null) { throw new Exception("Animal não encontrado"); } animalRepository.Delete(animal); }
public void DeleteAnimals(Animalpar model) { using (var animal = new AnimalRepository()) { Animal ani = animal.GetById(model.AnimalId); if (ani != null) { animal.Delete(ani); } } }
public ActionResult Delete(int id, [FromServices] DataContext context) { try { _repository.Delete(id); return(Ok(new { message = "Animal removido com sucesso." })); } catch { return(BadRequest(new { message = "Não foi possível remover o animal." })); } }
private void buttonDeleteAnimal_Click(object sender, EventArgs e) { if (dataGridViewAnimals.CurrentRow == null) { return; } var selectedOwner = (Animal)dataGridViewAnimals.CurrentRow.DataBoundItem; using (RepositoryContext db = new RepositoryContext("RepositoryContext")) { AnimalRepository animalRepo = new AnimalRepository(db); var animal = animalRepo.GetById(selectedOwner.Id); animalRepo.Delete(animal); animalRepo.SaveChanges(); } GetData(); }
static void Main(string[] args) { Animal first = new Animal { Id = 1, Name = "Bobita", Description = "Cat" }; Animal second = new Animal { Id = 2, Name = "Rex", Description = "Dog" }; Animal third = new Animal { Id = 3, Name = "Kitty", Description = "Cat" }; Animal fourth = new Animal { Id = 4, Name = "Daisy", Description = "Parrot" }; Animal fifth = new Animal { Id = 5, Name = "Max", Description = "Dog" }; AnimalRepository repo = new AnimalRepository(); repo.Add(first); repo.Add(second); repo.Add(third); repo.Add(fourth); repo.Add(fifth); Animal firstAnimal = repo.GetById(1); Animal secondAnimal = repo.GetById(2); IEnumerable <Animal> animalList = repo.GetAll(); Console.WriteLine(first); Console.WriteLine(second); Console.WriteLine("Before update: "); foreach (var a in animalList) { Console.WriteLine(a); } Console.WriteLine("After update: "); repo.Update(1, "Mickey", "Mouse"); foreach (var a in animalList) { Console.WriteLine(a); } Console.WriteLine("After removing nr. 4 : "); repo.Delete(4); foreach (var a in animalList) { Console.WriteLine(a); } Tiger tiger = new Tiger(); }