Ejemplo n.º 1
0
        public static void addIlnnessToDb(SharedModels.IllnessModel illness)
        {
            var illDb = db.TableIllness.Where(i => i.Name == illness.Name).ToList();

            var ilnessDb = new DbServices.Illness();

            if (illDb.Count == 0)
            {
                ilnessDb.Name = illness.Name;
                db.AddToTableIllness(ilnessDb);
                db.SaveChanges();
            }
            else
            {
                ilnessDb = illDb.First();
            }

            var pWasSick = new DbServices.PatientWasSick
            {
                Date        = illness.Date,
                Description = illness.Description,
                PatientId   = illness.IdPatient,
                Illness     = ilnessDb,
                IllnessId   = ilnessDb.Id
            };

            db.AddToTablePatientWasSick(pWasSick);
            db.SetLink(pWasSick, "Illness", ilnessDb);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (TBIllness.Text.CompareTo("") != 0 && datePicker1.Text.CompareTo("") != 0)
            {
                int      day     = int.Parse(datePicker1.Text.Substring(0, 2));
                int      month   = int.Parse(datePicker1.Text.Substring(3, 2));
                int      year    = int.Parse(datePicker1.Text.Substring(6, 4));
                DateTime dt      = new DateTime(year, month, day);
                Illness  illness = new Illness(TBIllness.Text, dt, TBDesc.Text);
                if (illnesses.myIllnesses == null)
                {
                    illnesses.myIllnesses = new List <Illness>();
                }
                if (UserPersister.User != null)
                {
                    var patientDb = db.TablePatient.Where(i => i.Pesel == UserPersister.User.Pesel);
                    var illDb     = db.TableIllness.Where(i => i.Name == illness.Name).ToList();
                    var ilnessDb  = new DbServices.Illness();

                    if (illDb.Count == 0)
                    {
                        ilnessDb.Name = illness.Name;
                        db.AddToTableIllness(ilnessDb);
                        db.SaveChanges();
                    }
                    else
                    {
                        ilnessDb = illDb.First();
                    }

                    var pWasSick = new DbServices.PatientWasSick
                    {
                        Date        = illness.Date,
                        Illness     = ilnessDb,
                        IllnessId   = ilnessDb.Id,
                        PatientId   = patientDb.First().Id,
                        Description = illness.Description
                    };
                    db.AddToTablePatientWasSick(pWasSick);
                    db.SetLink(pWasSick, "Illness", ilnessDb);
                    db.SaveChanges();
                }
                illnesses.myIllnesses.Add(illness);
                Close();
            }
        }