示例#1
0
        public void DeleteAdministrator(int id)
        {
            try
            {
                using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
                //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
                {
                    Administrator administrator = context.Administrator.Include(p => p.Person).FirstOrDefault(p => p.Id == id);

                    if (administrator != null)
                    {
                        administrator.Person = context.Person.FirstOrDefault(p => p.Id == administrator.PersonId);

                        if (administrator.Person != null)
                        {
                            //Bad code: place holder
                            administrator.Person.Email    = "*****@*****.**";
                            administrator.Person.UserName = "******";
                            administrator.Person.Active   = false;
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                //throw ex;
            }
        }
示例#2
0
        public void SaveAdministrator(Administrator administrator)
        {
            try
            {
                using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
                //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
                {
                    if (administrator.Id > 0)
                    {
                        Administrator savedAdministrator = context.Administrator.FirstOrDefault(p => p.Id == administrator.Id);

                        if (savedAdministrator != null)
                        {
                            savedAdministrator = administrator;
                        }
                    }
                    else
                    {
                        context.Administrator.Add(administrator);
                    }
                    context.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        public void SaveDoctor(Doctor doctor)
        {
            try
            {
                using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
                {
                    if (doctor.Id > 0)
                    {
                        Doctor savedDoctor = context.Doctor.FirstOrDefault(p => p.Id == doctor.Id);

                        if (savedDoctor != null)
                        {
                            savedDoctor = doctor;
                        }
                    }
                    else
                    {
                        context.Doctor.Add(doctor);
                    }
                    context.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        public void SaveNurse(Nurse nurse)
        {
            try
            {
                using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
                //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
                {
                    if (nurse.Id > 0)
                    {
                        Nurse savedNurse = context.Nurse.FirstOrDefault(p => p.Id == nurse.Id);

                        if (savedNurse != null)
                        {
                            savedNurse = nurse;
                        }
                    }
                    else
                    {
                        context.Nurse.Add(nurse);
                    }
                    context.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
        public void SavePorter(Porter porter)
        {
            try
            {
                using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
                {
                    if (porter.Id > 0)
                    {
                        Porter savedPorter = context.Porter.FirstOrDefault(p => p.Id == porter.Id);

                        if (savedPorter != null)
                        {
                            savedPorter = porter;
                        }
                    }
                    else
                    {
                        context.Porter.Add(porter);
                    }
                    context.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        public Doctor Retrieve(string identityNumber)
        {
            Doctor result = null;

            using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
            {
                result = context.Doctor.FirstOrDefault(p => p.Person.IdNumber == identityNumber);
            }
            return(result);
        }
        public List <Doctor> GetAllDoctors()
        {
            List <Doctor> result = null;

            using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
            {
                result = context.Doctor.ToList();
            }

            return(result);
        }
示例#8
0
        public Patient Retrieve(string identityNumber)
        {
            Patient result = null;


            using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
            //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
            {
                result = context.Patient.FirstOrDefault(p => p.Person.IdNumber == identityNumber);
            }
            return(result);
        }
示例#9
0
 public void SavePatient(Patient patient)
 {
     try
     {
         using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
         //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
         {
             context.Patient.Add(patient);
             context.SaveChanges();
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
示例#10
0
        public List <Administrator> GetAllAdministrators()
        {
            List <Administrator> result = null;

            using (HospitalManagementSystemContext context = TypeFactory.Resolve <HospitalManagementSystemContext>())
            //using (HospitalManagementSystemContext context = new HospitalManagementSystemContext())
            {
                result = context.Administrator.Include(p => p.Person).Where(p => p.Person.Active).ToList();

                //Hack because inclusions are not working
                foreach (var administrator in result)
                {
                    administrator.Person = context.Person.FirstOrDefault(p => p.Id == administrator.PersonId);
                }
            }

            return(result);
        }