private static void Main(string[] args)
        {
            HospitalContext context = new HospitalContext();

            Patient patient = new Patient()
            {
                FirstName   = "Ivan",
                LastName    = "Ivanov",
                Address     = "Mladost 1",
                Email       = "*****@*****.**",
                DateOfBirth = DateTime.Now
            };

            context.Patients.Add(patient);

            Visitation visitation = new Visitation()
            {
                Patient = patient,
                Date    = DateTime.Now
            };

            context.Visitations.Add(visitation);

            Diagnose diagnose = new Diagnose()
            {
                Name    = "Disease",
                Patient = patient
            };

            context.Diagnoses.Add(diagnose);

            Medicament medicament = new Medicament()
            {
                Name = "Vitamin C",
            };

            medicament.Patients.Add(patient);

            context.Medicaments.Add(medicament);

            Doctor doctor = new Doctor()
            {
                Name      = "Dr. Ivanov",
                Specialty = "orthopedic doctor"
            };

            visitation.Doctor = doctor;

            context.Doctors.Add(doctor);

            try
            {
                context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var ev in ex.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      ev.Entry.Entity.GetType().Name, ev.Entry.State);
                    foreach (var ve in ev.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
Exemplo n.º 2
0
        public static void Init(HospitalContext context)
        {
            if (!context.Diagnoses.Any())
            {
                context.Diagnoses.AddRange(
                    new Diagnosis
                {
                    Title     = "pneumonia",
                    DeathRate = 50
                },
                    new Diagnosis
                {
                    Title     = "tuberculosis",
                    DeathRate = 66
                },
                    new Diagnosis
                {
                    Title     = "blood cancer",
                    DeathRate = 84
                },
                    new Diagnosis
                {
                    Title     = "narcolepsy",
                    DeathRate = 47
                },
                    new Diagnosis
                {
                    Title     = "schizophrenia",
                    DeathRate = 7
                },
                    new Diagnosis
                {
                    Title     = "lupis",
                    DeathRate = 65
                }

                    );
                context.SaveChanges();
            }
            if (!context.Doctors.Any())
            {
                context.Doctors.AddRange(
                    new Doctors
                {
                    Name       = "Tom",
                    Speciality = "Pulmonologist",
                    Skill      = 54
                },
                    new Doctors
                {
                    Name       = "Hamilton",
                    Speciality = "Psychiatrist",
                    Skill      = 67
                },
                    new Doctors
                {
                    Name       = "James",
                    Speciality = "Oncologist",
                    Skill      = 70
                },
                    new Doctors
                {
                    Name       = "Alexceander",
                    Speciality = "Rheumatologist",
                    Skill      = 50
                }
                    );
                context.SaveChanges();
            }
        }
        public static void Main()
        {
            try
            {
                var context = new HospitalContext();

                using (context)
                {
                    //context.Database.Initialize(true);

                    Patient patient = new Patient
                    {
                        FirstName   = "Marrika",
                        LastName    = "Obstova",
                        Adress      = "Luvov most No.1",
                        Email       = "*****@*****.**",
                        DateOfBirth = new DateTime(1990, 05, 07)
                    };

                    Doctor doctor = new Doctor
                    {
                        Name      = "Doctor Frankenstein",
                        Specialty = "Mad scientist"
                    };

                    Visitation visitation = new Visitation
                    {
                        Doctor   = doctor,
                        Comments = "Mnoo zle",
                        Patient  = patient,
                        Date     = DateTime.Now
                    };

                    patient.Visitations.Add(visitation);
                    doctor.Visitations.Add(visitation);

                    Diagnose diagnose = new Diagnose
                    {
                        Name     = "HIV",
                        Comments = "Ot mangalite na luvov most",
                        Patient  = patient
                    };

                    patient.Diagnoses.Add(diagnose);

                    Medicament medicament = new Medicament
                    {
                        Name    = "Paracetamol",
                        Patient = patient
                    };

                    patient.Medicaments.Add(medicament);

                    context.Patients.Add(patient);
                    context.Doctors.Add(doctor);
                    context.Diagnoses.Add(diagnose);
                    context.Visitations.Add(visitation);
                    context.Medicaments.Add(medicament);
                    context.SaveChanges();
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult dbEntityValidationResult in ex.EntityValidationErrors)
                {
                    foreach (DbValidationError dbValidationError in dbEntityValidationResult.ValidationErrors)
                    {
                        Console.WriteLine(dbValidationError.ErrorMessage);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public static void Init(HospitalContext context)
 {
     if (!context.Patients.Any())
     {
         context.Patients.AddRange(
             new Patient
         {
             Name        = "Mark",
             DiagnosisId = 5,
             ArrivalDate = new System.DateTime(1996, 6, 3, 22, 15, 0)
         },
             new Patient
         {
             Name        = "Tom",
             DiagnosisId = 3,
             ArrivalDate = new DateTime(1996, 12, 6, 13, 2, 0)
         },
             new Patient
         {
             Name        = "Andrew",
             DiagnosisId = 4,
             ArrivalDate = new DateTime(1996, 6, 3, 22, 15, 0)
         }
             );
         context.SaveChanges();
     }
     if (!context.Diagnoses.Any())
     {
         context.Diagnoses.AddRange(
             new Diagnosis
         {
             Title     = "pneumonia",
             DeathRate = 50
         },
             new Diagnosis
         {
             Title     = "tuberculosis",
             DeathRate = 58
         },
             new Diagnosis
         {
             Title     = "blood cancer",
             DeathRate = 87
         },
             new Diagnosis
         {
             Title     = "narcolepsy",
             DeathRate = 27
         },
             new Diagnosis
         {
             Title     = "schizophrenia",
             DeathRate = 39
         },
             new Diagnosis
         {
             Title     = "lupis",
             DeathRate = 71
         }
             );
         context.SaveChanges();
     }
 }