示例#1
0
        public static bool VisitAddOrUpdate(Visit visit)
        {
            if (Clinic.IsConnected)
            {
                using (Clinic db = new Clinic(Clinic.currentConnection))
                {
                    try
                    {
                        db.Patients.Load();
                        db.Visits.Load();
                        //Visit does not present. Creating
                        if (visit.Id == -1 && visit.patient != null)
                        {
                            var p = db.Patients.FirstOrDefault(x => x.Id == visit.patient.Id);
                            visit.patient = p;

                            db.Visits.Add(visit);
                            db.SaveChanges();
                        }
                        //Editing Visit
                        else
                        {
                            var v = db.Visits.FirstOrDefault(x => x.Id == visit.Id);
                            if (v != null && visit.patient != null)
                            {
                                var p = db.Patients.FirstOrDefault(x => x.Id == visit.patient.Id);
                                v.patient = p;
                                db.Entry(v).CurrentValues.SetValues(visit);
                                db.SaveChanges();
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
示例#2
0
 public static bool PatientAddOrUpdate(Patient patient)
 {
     if (Clinic.IsConnected)
     {
         using (Clinic db = new Clinic(Clinic.currentConnection))
         {
             try
             {
                 db.Patients.Load();
                 //Patient does not present. Creating
                 if (patient.Id == -1)
                 {
                     db.Patients.Add(patient);
                     db.SaveChanges();
                 }
                 //Editing Patient
                 else
                 {
                     var p = db.Patients.FirstOrDefault(x => x.Id == patient.Id);
                     if (p != null)
                     {
                         db.Entry(p).CurrentValues.SetValues(patient);
                         db.SaveChanges();
                     }
                     else
                     {
                         return(false);
                     }
                 }
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
     }
     else
     {
         return(false);
     }
 }