Ejemplo n.º 1
0
        private void CreateAnimal_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                var editedAnimal = _context.Animals.FirstOrDefault(x => x.Id == _animalId);

                if (editedAnimal == null)
                {
                    editedAnimal = new Animal();
                }

                editedAnimal.Name = tbName.Text.Trim();
                editedAnimal.Size = (AnimalSize)cbSize.SelectedItem;

                _context.Animals.AddOrUpdate(editedAnimal);
                _context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 private void DeleteAnimal(Animal deletedAnimal)
 {
     _context.Animals.Remove(deletedAnimal);
     _context.SaveChanges();
 }