public static void AddNewClinic(Clinic clinic) { HealthCareEntities hlthCareContext = new HealthCareEntities(); hlthCareContext.Clinics.Add(clinic); hlthCareContext.SaveChanges(); }
public ClinicForm(int cmd, Clinic cl) { InitializeComponent(); this.cl = cl; flagEdit = false; switch (cmd) { case 0: FormForEdit(); break; case 1: FormForAdd(); break; default: throw new Exception("Not correct parametr to constructor for ClinicForm!"); } }
public static void UpdateClinic(Clinic clinic) { HealthCareEntities hlthCareContext = new HealthCareEntities(); var cl = hlthCareContext.Clinics.Where(c => c.Id == clinic.Id).First(); cl.Title = clinic.Title; cl.Phone = clinic.Phone; cl.Address = clinic.Address; hlthCareContext.SaveChanges(); }
public static void DeleteClinic(int id) { HealthCareEntities hlthCareContext = new HealthCareEntities(); Clinic clinic = new Clinic() { Id = id }; hlthCareContext.Clinics.Attach(clinic); hlthCareContext.Clinics.Remove(clinic); hlthCareContext.SaveChanges(); }
private void SetChangesToDB() { using (HealthCareEntities healthCareContext = new HealthCareEntities()) { try { GetDataFromForms(); if (cl.Id != 0) { Clinic.UpdateClinic(cl); } else { Clinic clinic = new Clinic() { Phone = cl.Phone, Title = cl.Title, Address = cl.Address }; Clinic.AddNewClinic(clinic); } } catch (Exception exp) { MessageBox.Show("Error! " + exp.Message); } } }
public ClinicForm() { InitializeComponent(); cl = new Clinic(); flagEdit = false; }