public static tblClinicMaintenance AddMaintenance(tblClinicMaintenance m)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (m.maintenanceId == 0)
             {
                 //add
                 tblClinicMaintenance newM = new tblClinicMaintenance();
                 newM.name = m.name;
                 newM.permissionToExpand      = m.permissionToExpand;
                 newM.accessibilityOfInvalids = m.accessibilityOfInvalids;
                 context.tblClinicMaintenances.Add(newM);
                 context.SaveChanges();
                 m.maintenanceId = newM.maintenanceId;
                 return(m);
             }
             else
             {
                 tblClinicMaintenance mToEdit = (from x in context.tblClinicMaintenances where x.maintenanceId == m.maintenanceId select x).FirstOrDefault();
                 mToEdit.name = m.name;
                 mToEdit.accessibilityOfInvalids = m.accessibilityOfInvalids;
                 mToEdit.permissionToExpand      = m.permissionToExpand;
                 context.SaveChanges();
                 return(m);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
        public static tblClinicAdministrator AddAdministrator(tblClinicAdministrator admin)
        {
            try
            {
                using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
                {
                    if (admin.adminId == 0)
                    {
                        //add
                        tblClinicAdministrator newAdmin = new tblClinicAdministrator();
                        //newAdmin.instituteId = editClinic.instituteId;
                        newAdmin.userId = admin.userId;
                        context.tblClinicAdministrators.Add(newAdmin);
                        context.SaveChanges();
                        admin.adminId = newAdmin.adminId;
                        return(admin);
                    }
                    else
                    {
                        tblClinicAdministrator adminToEdit = (from x in context.tblClinicAdministrators where x.adminId == admin.adminId select x).FirstOrDefault();
                        adminToEdit.userId      = admin.userId;
                        adminToEdit.instituteId = admin.instituteId;

                        context.SaveChanges();
                        return(admin);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
                return(null);
            }
        }
        public static tblInstitute AddInstitute(tblInstitute clinic)
        {
            try
            {
                using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
                {
                    if (clinic.instituteId == 0)
                    {
                        //add
                        tblInstitute newInstitute = new tblInstitute();
                        newInstitute.instituteOwner = clinic.instituteOwner;
                        newInstitute.name           = clinic.name;
                        newInstitute.numberOfAccessPointsForInvalids = clinic.numberOfAccessPointsForInvalids;
                        newInstitute.numberOfAmbulanceAccessPoints   = clinic.numberOfAmbulanceAccessPoints;
                        newInstitute.numberOfFloors   = clinic.numberOfFloors;
                        newInstitute.numberOfRooms    = clinic.numberOfRooms;
                        newInstitute.terrace          = clinic.terrace;
                        newInstitute.yard             = clinic.yard;
                        newInstitute.address          = clinic.address;
                        newInstitute.constructionDate = clinic.constructionDate;
                        context.tblInstitutes.Add(newInstitute);
                        context.SaveChanges();
                        clinic.instituteId = newInstitute.instituteId;
                        return(clinic);
                    }
                    else
                    {
                        tblInstitute instituteToEdit = (from x in context.tblInstitutes where x.instituteId == clinic.instituteId select x).FirstOrDefault();
                        instituteToEdit.address          = clinic.address;
                        instituteToEdit.constructionDate = clinic.constructionDate;
                        instituteToEdit.instituteOwner   = clinic.instituteOwner;
                        instituteToEdit.name             = clinic.name;
                        instituteToEdit.numberOfAccessPointsForInvalids = clinic.numberOfAccessPointsForInvalids;
                        instituteToEdit.numberOfAmbulanceAccessPoints   = clinic.numberOfAmbulanceAccessPoints;
                        instituteToEdit.numberOfFloors = clinic.numberOfFloors;
                        instituteToEdit.numberOfRooms  = clinic.numberOfRooms;
                        instituteToEdit.terrace        = clinic.terrace;
                        instituteToEdit.yard           = clinic.yard;
                        instituteToEdit.instituteOwner = clinic.instituteOwner;

                        context.SaveChanges();
                        return(clinic);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
                return(null);
            }
        }
 public static tblUser AddUser(tblUser user)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (user.userId == 0)
             {
                 //add
                 tblUser newUser = new tblUser();
                 newUser.username    = user.username;
                 newUser.password    = user.password;
                 newUser.ICnumber    = user.ICnumber;
                 newUser.gender      = user.gender;
                 newUser.dateOfBirth = user.dateOfBirth;
                 newUser.citizenship = user.citizenship;
                 newUser.fullname    = user.fullname;
                 context.tblUsers.Add(newUser);
                 context.SaveChanges();
                 user.userId = newUser.userId;
                 return(user);
             }
             else
             {
                 tblUser userToEdit = (from x in context.tblUsers where x.userId == user.userId select x).FirstOrDefault();
                 userToEdit.username    = user.username;
                 userToEdit.password    = user.password;
                 userToEdit.gender      = user.gender;
                 userToEdit.fullname    = user.fullname;
                 userToEdit.citizenship = user.citizenship;
                 userToEdit.dateOfBirth = user.dateOfBirth;
                 userToEdit.ICnumber    = user.ICnumber;
                 context.SaveChanges();
                 return(user);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
 public static tblClinicDoctor AddDoctor(tblClinicDoctor doctor)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (doctor.doctorId == 0)
             {
                 //add
                 tblClinicDoctor newDoctor = new tblClinicDoctor();
                 newDoctor.account             = doctor.account;
                 newDoctor.admissionOfPatients = doctor.admissionOfPatients;
                 newDoctor.department          = doctor.department;
                 newDoctor.managerId           = doctor.managerId;
                 newDoctor.shift  = doctor.shift;
                 newDoctor.userId = doctor.userId;
                 context.tblClinicDoctors.Add(newDoctor);
                 context.SaveChanges();
                 doctor.doctorId = newDoctor.doctorId;
                 return(doctor);
             }
             else
             {
                 tblClinicDoctor doctorToEdit = (from x in context.tblClinicDoctors where x.doctorId == doctor.doctorId select x).FirstOrDefault();
                 doctorToEdit.account             = doctor.account;
                 doctorToEdit.admissionOfPatients = doctor.admissionOfPatients;
                 doctorToEdit.department          = doctor.department;
                 doctorToEdit.managerId           = doctor.managerId;
                 doctorToEdit.userId = doctor.userId;
                 doctorToEdit.shift  = doctor.shift;
                 context.SaveChanges();
                 return(doctor);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
 public static tblClinicManager AddManager(tblClinicManager manager)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (manager.managerId == 0)
             {
                 //add
                 tblClinicManager newManager = new tblClinicManager();
                 newManager.floorNumber        = manager.floorNumber;
                 newManager.maxNumberOfDoctors = manager.maxNumberOfDoctors;
                 newManager.minNumberOfRooms   = manager.minNumberOfRooms;
                 newManager.numberOfOmissions  = manager.numberOfOmissions;
                 newManager.userId             = manager.userId;
                 context.tblClinicManagers.Add(newManager);
                 context.SaveChanges();
                 manager.managerId = newManager.managerId;
                 return(manager);
             }
             else
             {
                 tblClinicManager managerToEdit = (from x in context.tblClinicManagers where x.managerId == manager.managerId select x).FirstOrDefault();
                 managerToEdit.floorNumber        = manager.floorNumber;
                 managerToEdit.maxNumberOfDoctors = manager.maxNumberOfDoctors;
                 managerToEdit.minNumberOfRooms   = manager.minNumberOfRooms;
                 managerToEdit.numberOfOmissions  = manager.numberOfOmissions;
                 managerToEdit.userId             = manager.userId;
                 context.SaveChanges();
                 return(manager);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
 public static tblClinicPatient AddPatient(tblClinicPatient patient)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (patient.patientId == 0)
             {
                 //add
                 tblClinicPatient newPatient = new tblClinicPatient();
                 newPatient.expiryDate = patient.expiryDate;
                 newPatient.cardNumber = patient.cardNumber;
                 newPatient.userId     = patient.userId;
                 context.tblClinicPatients.Add(newPatient);
                 context.SaveChanges();
                 patient.patientId = newPatient.patientId;
                 return(patient);
             }
             else
             {
                 tblClinicPatient patientToEdit = (from x in context.tblClinicPatients where x.patientId == patient.patientId select x).FirstOrDefault();
                 patientToEdit.expiryDate = patient.expiryDate;
                 patientToEdit.hasVirus   = patient.hasVirus;
                 patientToEdit.userId     = patient.userId;
                 patientToEdit.cardNumber = patient.cardNumber;
                 patientToEdit.doctorId   = patient.doctorId;
                 context.SaveChanges();
                 return(patient);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
 public static void DeleteDoctor(tblClinicDoctor doctor)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             tblClinicDoctor toDelete = (from u in context.tblClinicDoctors where u.doctorId == doctor.doctorId select u).First();
             context.tblClinicDoctors.Remove(toDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
 public static void DeleteMaintenance(tblClinicMaintenance maintenance)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             tblClinicMaintenance toDelete = (from u in context.tblClinicMaintenances where u.maintenanceId == maintenance.maintenanceId select u).First();
             context.tblClinicMaintenances.Remove(toDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }