public static Diagnosis GetDiagnosisById(int diagnosisId)
 {
     MedicalCardEntities context = new MedicalCardEntities();
     var diagnosis = context.Diagnoses.Where(p => p.DiagnoseId == diagnosisId).FirstOrDefault();
     context.Detach(diagnosis);
     return diagnosis;
 }
 public static Doctor GetDoctorById(int doctorId)
 {
     MedicalCardEntities context = new MedicalCardEntities();
     var doctor = context.Doctors.Where(p => p.DoctorId == doctorId).FirstOrDefault();
     if (doctor != null)
     {
         context.Detach(doctor);
     }
     return doctor;
 }
 public static Patient GetPatientWithConsultationsAndDiagnosesById(int patientId)
 {
     MedicalCardEntities context = new MedicalCardEntities();
     var patient = context.Patients
                         .Include("Consultations")
                         .Include("Diagnoses")
                         .Where(p => p.PatientId == patientId)
                         .FirstOrDefault();
     context.Detach(patient);
     return patient;
 }
 public static Consultation GetConsultationById(int consultationId)
 {
     MedicalCardEntities context = new MedicalCardEntities();
     var consultation = context
                         .Consultations
                         .Include("Doctor")
                         .Include("Patient")
                         .Where(p => p.ConsultationId == consultationId)
                         .FirstOrDefault();
     //detaching the object - ablity to share between different contexts
     context.Detach(consultation);
     return consultation;
 }
        public static void InsertPatient(Patient patient)
        {
            MedicalCardEntities context = new MedicalCardEntities();
            if (patient.EntityState != EntityState.Detached)
            {
                context.ObjectStateManager.ChangeObjectState(patient, EntityState.Added);
            }
            else
            {
                context.Patients.AddObject(patient);
            }
            context.SaveChanges();

            //detach because object is stateless
            context.Detach(patient);
        }
        public static void UpdatePatient(Patient patient)
        {
            MedicalCardEntities context = new MedicalCardEntities();
            context.Patients.AddObject(patient);
            context.ObjectStateManager.ChangeObjectState(patient, EntityState.Modified);
            context.SaveChanges();

            //detach because object is stateless
            context.Detach(patient);
        }
 public static void InsertConsultation(Consultation consultation)
 {
     MedicalCardEntities context = new MedicalCardEntities();
     if (consultation.EntityState != EntityState.Detached)
     {
         context.ObjectStateManager.ChangeObjectState(consultation, EntityState.Added);
     }
     else
     {
         context.Consultations.AddObject(consultation);
     }
     context.SaveChanges();
     //detaching the object - ablity to share between different contexts
     context.Detach(consultation);
 }
        public static void UpdateConsultation(Consultation consultation)
        {
            MedicalCardEntities context = new MedicalCardEntities();
            context.Consultations.AddObject(consultation);
            context.ObjectStateManager.ChangeObjectState(consultation, EntityState.Modified);
            context.SaveChanges();

            //detaching the object - ablity to share between different contexts
            context.Detach(consultation);
        }