Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        private void buttonAddVisit_Click(object sender, EventArgs e)
        {
            if (comboBoxVets.SelectedItem == null ||
                comboBoxOwnersFromVisit.SelectedItem == null ||
                comboBoxAnimals.SelectedItem == null)
            {
                return;
            }


            int ownerId  = ((Owner)comboBoxOwnersFromVisit.SelectedItem).Id;
            int vetId    = ((Vet)comboBoxVets.SelectedItem).Id;
            int animalId = ((Animal)comboBoxAnimals.SelectedItem).Id;

            int cost = 0;

            try
            {
                cost = Int32.Parse(textBoxVisitCost.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Zły format ceny");
            }


            Visit newVisit = new Visit
            {
                Description = textBoxVisitDescription.Text,
                Cost        = cost,
                Date        = dateTimePickerAnimalDate.Value,
                OwnerId     = ownerId,
                VetId       = vetId,
                AnimalId    = animalId
            };

            textBoxVisitDescription.Text = "";
            textBoxVisitCost.Text        = "";
            dateTimePickerVisitData.Text = "";

            using (RepositoryContext db = new RepositoryContext("RepositoryContext"))
            {
                AnimalRepository animalRepo = new AnimalRepository(db);
                OwnerRepository  ownerRepo  = new OwnerRepository(db);
                VetRepository    vetRepo    = new VetRepository(db);
                VisitRepository  visitRepo  = new VisitRepository(db);

                var owner  = ownerRepo.GetById(ownerId);
                var vet    = vetRepo.GetById(vetId);
                var animal = animalRepo.GetById(animalId);

                newVisit.Owner  = owner;
                newVisit.Vet    = vet;
                newVisit.Animal = animal;

                var visit = visitRepo.Add(newVisit);
                visitRepo.SaveChanges();
            }


            GetData();
        }