public static void AddNewPatient(Patient patient) { HealthCareEntities hlthCareContext = new HealthCareEntities(); hlthCareContext.Patients.Add(patient); hlthCareContext.SaveChanges(); }
public static void UpdatePatient(Patient patient) { HealthCareEntities hlthCareContext = new HealthCareEntities(); var pt = hlthCareContext.Patients.Where(p => p.Id == patient.Id).First(); pt.Name = patient.Name; pt.Phone = patient.Phone; pt.Address = patient.Address; hlthCareContext.SaveChanges(); }
public PatientForm(int cmd, Patient pt) { InitializeComponent(); this.pt = pt; flagEdit = false; switch (cmd) { case 0: FormForEdit(); break; case 1: FormForAdd(); break; default: throw new Exception("Not correct parametr to constructor for PatientForm!"); } }
public static void DeletePatient(int id) { HealthCareEntities hlthCareContext = new HealthCareEntities(); Patient patient = new Patient { Id = id }; hlthCareContext.Patients.Attach(patient); hlthCareContext.Patients.Remove(patient); hlthCareContext.SaveChanges(); }
private void SetChangesToDB() { using (HealthCareEntities healthCareContext = new HealthCareEntities()) { try { GetDataFromForms(); if (pt.Id != 0) { Patient.UpdatePatient(pt); } else { Patient patient = new Patient() { Phone = pt.Phone, Name =pt.Name, Address = pt.Address }; Patient.AddNewPatient(patient); } } catch (Exception exp) { MessageBox.Show("Error! " + exp.Message); } } }
public PatientForm() { InitializeComponent(); pt = new Patient(); flagEdit = false; }