public ActionResult Delete(int id)
        {
            AnimalRepository animalRep = new AnimalRepository();

            animalRep.Delete(id);

            return(RedirectToAction("List"));
        }
Exemplo n.º 2
0
        public void Delete(long id)
        {
            Animal animal = animalRepository.GetById(id);

            if (animal == null)
            {
                throw new Exception("Animal não encontrado");
            }

            animalRepository.Delete(animal);
        }
Exemplo n.º 3
0
 public void DeleteAnimals(Animalpar model)
 {
     using (var animal = new AnimalRepository())
     {
         Animal ani = animal.GetById(model.AnimalId);
         if (ani != null)
         {
             animal.Delete(ani);
         }
     }
 }
Exemplo n.º 4
0
 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." }));
     }
 }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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();
        }