public static List <PatientAtFoodPlace> CreatePatientAtFoodPlaces(int userinput) { WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient(); List <WpfWebClient.ServiceReferenceEHEC.FoodPlace> foodPlaces = new List <ServiceReferenceEHEC.FoodPlace>(client.GetFoodPlaces()); List <WpfWebClient.ServiceReferenceEHEC.Person> patients = new List <ServiceReferenceEHEC.Person>(client.GetPersons()); int i = 0; do { PatientAtFoodPlace patfgen = new PatientAtFoodPlace(); int randnumFP = random.Next(0, foodPlaces.Count()); FoodPlace foodpl = foodPlaces[randnumFP]; int randnumP = random.Next(0, patients.Count()); Person patient = patients[randnumP]; patfgen.FoodPlace = foodpl; patfgen.Patient = patient; patfgen.VistingDate = new DateTime(2005, 12, 20); PatientsAtFoodPlaces.Add(patfgen); i++; } while (i < userinput); client.Close(); return(PatientsAtFoodPlaces); }
public bool DeleteRelation(PatientAtFoodPlace patientAtFoodPlace) { try { using (Context ctx = new Context()) { ctx.PatientAtFoodPlaces.Attach(patientAtFoodPlace); ctx.PatientAtFoodPlaces.Remove(patientAtFoodPlace); ctx.SaveChanges(); } return(true); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e); return(false); } }
public bool UpdateRelation(PatientAtFoodPlace patientAtFoodPlace) { try { using (Context ctx = new Context()) { ctx.PatientAtFoodPlaces.Attach(patientAtFoodPlace); ctx.Entry(patientAtFoodPlace).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } return(true); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e); return(false); } }
public bool CreateRelation(PatientAtFoodPlace patientAtFoodPlace) { try { using (Context ctx = new Context()) { var patient = ctx.Persons.FirstOrDefault(p => p.PersonID == patientAtFoodPlace.Patient.PersonID); var foodplace = ctx.FoodPlaces.FirstOrDefault(f => f.FoodPlaceID == patientAtFoodPlace.FoodPlace.FoodPlaceID); var pcity = ctx.Cities.FirstOrDefault(c => c.CityID == patient.City.CityID); var fcity = ctx.Cities.FirstOrDefault(c => c.CityID == patientAtFoodPlace.FoodPlace.City.CityID); var pcountry = ctx.Countries.FirstOrDefault(c => c.CountryID == pcity.Country.CountryID); var fcountry = ctx.Countries.FirstOrDefault(c => c.CountryID == fcity.Country.CountryID); var salutation = ctx.Salutations.FirstOrDefault(s => s.SalutationID == patient.Salutation.SalutationID); var gender = ctx.Genders.FirstOrDefault(g => g.GenderID == patient.Gender.GenderID); ctx.Cities.Attach(pcity); ctx.Cities.Attach(fcity); ctx.Countries.Attach(pcountry); ctx.Countries.Attach(fcountry); ctx.Genders.Attach(gender); ctx.Salutations.Attach(salutation); ctx.Persons.Attach(patient); ctx.FoodPlaces.Attach(foodplace); patientAtFoodPlace.FoodPlace = foodplace; patientAtFoodPlace.Patient = patient; ctx.PatientAtFoodPlaces.Add(patientAtFoodPlace); ctx.SaveChanges(); } return(true); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e); return(false); } }
private void btnAddFoodPlace_Click(object sender, RoutedEventArgs e) { WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient(); Exam exam = new Exam(); // check if any box is empty if (ComboBoxDoctors.SelectedIndex == -1) { System.Windows.MessageBox.Show("Please choose a doctor", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } if (dateboxExamDate.SelectedDate == null) { System.Windows.MessageBox.Show("Please enter a date of consultation", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } if (ComboBoxPatients.SelectedIndex == -1) { System.Windows.MessageBox.Show("No Patient? Really?", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } if (ComboBoxStrains.SelectedIndex == -1) { System.Windows.MessageBox.Show("Why would you fill out an exam when there is no strain?", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } else { exam.Date = dateboxExamDate.SelectedDate.Value; exam.Doctor = (Doctor)ComboBoxDoctors.SelectedValue; exam.Patient = (Person)ComboBoxPatients.SelectedValue; exam.Description = txtDescription.Text; exam.Strain = (Strain)ComboBoxStrains.SelectedValue; client.WriteExam(exam); } PatientAtFoodPlace patf = new PatientAtFoodPlace(); // check if any box is empty if (ComboBoxFoodPlace.SelectedIndex == -1) { System.Windows.MessageBox.Show("Please choose a food place", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } if (dateboxFoodplaceDate.SelectedDate == null) { System.Windows.MessageBox.Show("Please enter a date at Foodplace", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } else { patf.FoodPlace = (FoodPlace)ComboBoxFoodPlace.SelectedValue; patf.Patient = (Person)ComboBoxPatients.SelectedValue; patf.PatientID = ComboBoxPatients.SelectedIndex; patf.VistingDate = dateboxFoodplaceDate.SelectedDate.Value; client.WriteRelation(patf); // Show success msgbox System.Windows.MessageBox.Show("Success", "INFO", MessageBoxButton.OK, MessageBoxImage.Information); } client.Close(); }
public void WriteRelation(PatientAtFoodPlace relation) { PatientAtFoodPlaceDB dataaccess = new PatientAtFoodPlaceDB(); dataaccess.CreateRelation(relation); }