Пример #1
0
        private void AddNewVet_Click(object sender, EventArgs e)
        {
            Vet newVet = new Vet
            {
                Name        = textBoxVetName.Text,
                Surname     = textBoxVetSurname.Text,
                LicenceNo   = textBoxVetLicenceNo.Text,
                Email       = textBoxVetEmail.Text,
                PhoneNumber = textBoxVetPhoneNumber.Text
            };

            textBoxVetName.Text        = "";
            textBoxVetSurname.Text     = "";
            textBoxVetLicenceNo.Text   = "";
            textBoxVetEmail.Text       = "";
            textBoxVetPhoneNumber.Text = "";

            using (RepositoryContext db = new RepositoryContext("RepositoryContext"))
            {
                VetRepository vetRepo = new VetRepository(db);

                var vet = vetRepo.Add(newVet);
                vetRepo.SaveChanges();
            }


            GetData();
        }
Пример #2
0
        private void buttonDeleteVet_Click(object sender, EventArgs e)
        {
            if (dataGridViewVets.CurrentRow == null)
            {
                return;
            }

            var selectedVet = (Vet)dataGridViewVets.CurrentRow.DataBoundItem;

            using (RepositoryContext db = new RepositoryContext("RepositoryContext"))
            {
                VetRepository vetRepo = new VetRepository(db);

                var vet = vetRepo.GetById(selectedVet.Id);
                vetRepo.Delete(vet);
                vetRepo.SaveChanges();
            }


            GetData();
        }