/// <summary>
 /// This method edits data about doctor and save changes to database.
 /// </summary>
 /// <param name="doctor">Doctor to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditDoctor(vwClinicDoctor doctor)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicDoctor doctorToEdit = context.tblClinicDoctors.Where(x => x.DoctorId == doctor.DoctorId).FirstOrDefault();
             doctorToEdit.UniqueNumber    = doctor.UniqueNumber;
             doctorToEdit.SuperiorManager = doctor.SuperiorManager;
             doctorToEdit.Shift           = doctor.Shift;
             doctorToEdit.ResponsibleForPatientAdmission = doctor.ResponsibleForPatientAdmission;
             doctorToEdit.Department        = doctor.Department;
             doctorToEdit.BankAccountNumber = doctor.BankAccountNumber;
             context.SaveChanges();
             tblUser userToEdit = context.tblUsers.Where(x => x.UserId == doctor.UserId).FirstOrDefault();
             userToEdit.NameAndSurname     = doctor.NameAndSurname;
             userToEdit.IdentityCardNumber = doctor.IdentityCardNumber;
             userToEdit.Gender             = doctor.Gender;
             userToEdit.DateOfBirth        = doctor.DateOfBirth;
             userToEdit.Citizenship        = doctor.Citizenship;
             userToEdit.Username           = doctor.Username;
             userToEdit.Password           = Encryption.EncryptPassword(doctor.Password);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// This method edits data about maintenance and save changes to database.
 /// </summary>
 /// <param name="maintenance">Maintenance to be edited.</param>
 /// <returns>true if edited, false if not.</returns>
 public bool EditMaintenance(vwClinicMaintenance maintenance)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicMaintenance maintenanceToEdit = context.tblClinicMaintenances.Where(x => x.MaintenanceId == maintenance.MaintenanceId).FirstOrDefault();
             maintenanceToEdit.PermissionToExpandClinic = maintenance.PermissionToExpandClinic;
             maintenanceToEdit.ResponsibleForAccessibilityOfInvalids = maintenance.ResponsibleForAccessibilityOfInvalids;
             context.SaveChanges();
             tblUser userToEdit = context.tblUsers.Where(x => x.UserId == maintenance.UserId).FirstOrDefault();
             userToEdit.NameAndSurname     = maintenance.NameAndSurname;
             userToEdit.IdentityCardNumber = maintenance.IdentityCardNumber;
             userToEdit.Gender             = maintenance.Gender;
             userToEdit.DateOfBirth        = maintenance.DateOfBirth;
             userToEdit.Citizenship        = maintenance.Citizenship;
             userToEdit.Username           = maintenance.Username;
             userToEdit.Password           = Encryption.EncryptPassword(maintenance.Password);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method edits data about patient and save changes to database.
 /// </summary>
 /// <param name="patient">Patient to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditPatient(vwClinicPatient patient)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicPatient patientToEdit = context.tblClinicPatients.Where(x => x.PatientId == patient.PatientId).FirstOrDefault();
             patientToEdit.ExpirationDateOfHealthInsurance = patient.ExpirationDateOfHealthInsurance;
             patientToEdit.HealthInsuranceCardNumber       = patient.HealthInsuranceCardNumber;
             patientToEdit.UniqueNumberOfSelectedDoctor    = patient.UniqueNumberOfSelectedDoctor;
             context.SaveChanges();
             tblUser userToEdit = context.tblUsers.Where(x => x.UserId == patient.UserId).FirstOrDefault();
             userToEdit.NameAndSurname     = patient.NameAndSurname;
             userToEdit.IdentityCardNumber = patient.IdentityCardNumber;
             userToEdit.Gender             = patient.Gender;
             userToEdit.DateOfBirth        = patient.DateOfBirth;
             userToEdit.Citizenship        = patient.Citizenship;
             userToEdit.Username           = patient.Username;
             userToEdit.Password           = Encryption.EncryptPassword(patient.Password);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method adds clinic to DbSet and save changes to database.
 /// </summary>
 /// <param name="clinic">Clinic to be added.</param>
 /// <returns>true if added, false if not.</returns>
 public bool CreateClinic(vwClinic clinic)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinic newClinic = new tblClinic
             {
                 Address            = clinic.Address,
                 DateOfConstruction = clinic.DateOfConstruction.Date,
                 Name = clinic.Name,
                 NumberOfAccessPointsForAmbulanceCars = clinic.NumberOfAccessPointsForAmbulanceCars,
                 NumberOfAccessPointsForInvalids      = clinic.NumberOfAccessPointsForInvalids,
                 NumberOfFloors        = clinic.NumberOfFloors,
                 NumberOfRoomsPerFloor = clinic.NumberOfRoomsPerFloor,
                 Owner   = clinic.Owner,
                 Terrace = clinic.Terrace,
                 Yard    = clinic.Yard
             };
             context.tblClinics.Add(newClinic);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method edit data about manager and save changes to database.
 /// </summary>
 /// <param name="manager">Manager to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditManager(vwClinicManager manager)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicManager managerToEdit = context.tblClinicManagers.Where(x => x.ManagerId == manager.ManagerId).FirstOrDefault();
             managerToEdit.Floor = manager.Floor;
             managerToEdit.MaximumNumberOfSupervisedDoctors = manager.MaximumNumberOfSupervisedDoctors;
             managerToEdit.MinimumNumberOfSupervisedRooms   = manager.MinimumNumberOfSupervisedRooms;
             managerToEdit.NumberOfOmissions = manager.NumberOfOmissions;
             context.SaveChanges();
             tblUser userToEdit = context.tblUsers.Where(x => x.UserId == manager.UserId).FirstOrDefault();
             userToEdit.NameAndSurname     = manager.NameAndSurname;
             userToEdit.IdentityCardNumber = manager.IdentityCardNumber;
             userToEdit.Gender             = manager.Gender;
             userToEdit.DateOfBirth        = manager.DateOfBirth;
             userToEdit.Citizenship        = manager.Citizenship;
             userToEdit.Username           = manager.Username;
             userToEdit.Password           = Encryption.EncryptPassword(manager.Password);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method finds managers who can supervise. Number of ommisions cannot be higher than 5 and cannot violate the limit on the maximum number of doctors.
 /// </summary>
 /// <returns>List of managers.</returns>
 public List <vwClinicManager> ManagersWhoCanSupervise()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             var managers = context.vwClinicManagers.Where(x => x.NumberOfOmissions <= 5).ToList();
             List <vwClinicManager> managerWhoCanSupervise = new List <vwClinicManager>();
             foreach (var manager in managers)
             {
                 //finding number of doctors that this manager supervise
                 int numberOfDoctors = context.tblClinicDoctors.Where(x => x.SuperiorManager == manager.ManagerId).Count();
                 if (numberOfDoctors < manager.MaximumNumberOfSupervisedDoctors)
                 {
                     managerWhoCanSupervise.Add(manager);
                 }
             }
             return(managerWhoCanSupervise);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// This method adds administrator to DbSet and save changes to database.
 /// </summary>
 /// <param name="administrator">Administrator to be added.</param>
 /// <returns>True if added, false if not.</returns>
 public bool CreateAdministrator(vwClinicAdministrator administrator)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblUser user = new tblUser
             {
                 Citizenship        = administrator.Citizenship,
                 DateOfBirth        = administrator.DateOfBirth,
                 Gender             = administrator.Gender,
                 IdentityCardNumber = administrator.IdentityCardNumber,
                 NameAndSurname     = administrator.NameAndSurname,
                 Password           = Encryption.EncryptPassword(administrator.Password),
                 Username           = administrator.Username
             };
             context.tblUsers.Add(user);
             context.SaveChanges();
             administrator.UserId = user.UserId;
             tblClinicAdministrator newAdministrator = new tblClinicAdministrator
             {
                 UserId = administrator.UserId
             };
             context.tblClinicAdministrators.Add(newAdministrator);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method deleted manager from databas.
 /// </summary>
 /// <param name="manager">Manager to be deleted.</param>
 /// <returns>True if deleted, false if not.</returns>
 public bool DeleteManager(vwClinicManager manager)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicManager managerToDelete = context.tblClinicManagers.Where(x => x.ManagerId == manager.ManagerId).FirstOrDefault();
             //finding doctors supervised by this manager
             var doctors = context.tblClinicDoctors.Where(x => x.SuperiorManager == manager.ManagerId).ToList();
             if (doctors.Count > 0)
             {
                 foreach (var doctor in doctors)
                 {
                     doctor.SuperiorManager = null;
                     context.SaveChanges();
                 }
             }
             context.tblClinicManagers.Remove(managerToDelete);
             context.SaveChanges();
             tblUser userToDelete = context.tblUsers.Where(x => x.UserId == manager.UserId).FirstOrDefault();
             context.tblUsers.Remove(userToDelete);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// This method creates a list of data from table of all users.
 /// </summary>
 /// <returns>List of users.</returns>
 public List <tblUser> GetAllUsers()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             return(context.tblUsers.ToList());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
 /// <summary>
 /// This method return clinic from DbSet.
 /// </summary>
 /// <returns>Clinic if exists, null if not.</returns>
 public vwClinic ViewClinic()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             return(context.vwClinics.FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
 /// <summary>
 /// This method checks if clinic exists in database.
 /// </summary>
 /// <returns>True if exists, false if not.</returns>
 public bool CheckIfClinicExists()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             return(context.tblClinics.Any());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method creates a list of data from view of doctors.
 /// </summary>
 /// <returns>List of doctors.</returns>
 public List <vwClinicDoctor> ViewAllDoctors()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             return(context.vwClinicDoctors.ToList());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// This method finds doctor in DbSet with forwarded username and password.
        /// </summary>
        /// <param name="username">Doctor username.</param>
        /// <param name="password">Doctor password.</param>
        /// <returns>Doctor if finded, null if not.</returns>
        public vwClinicDoctor FindDoctor(string username, string password)
        {
            string encryptedPassword = Encryption.EncryptPassword(password);

            try
            {
                using (ClinicEntities context = new ClinicEntities())
                {
                    return(context.vwClinicDoctors.Where(x => x.Username == username && x.Password == encryptedPassword).FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
 /// <summary>
 /// This method edits data about clinic.
 /// </summary>
 /// <param name="clinic">Clinic to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditClinic(vwClinic clinic)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinic clinicToEdit = context.tblClinics.Where(x => x.ClinicId == clinic.ClinicId).FirstOrDefault();
             clinicToEdit.Owner = clinic.Owner;
             clinicToEdit.NumberOfAccessPointsForAmbulanceCars = clinic.NumberOfAccessPointsForAmbulanceCars;
             clinicToEdit.NumberOfAccessPointsForInvalids      = clinic.NumberOfAccessPointsForInvalids;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// This method finds first maintenance in database and then invokes method for deleting.
 /// </summary>
 public void DeleteFirst()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             Queue <vwClinicMaintenance> maintenances = new Queue <vwClinicMaintenance>(3);
             var maintenancesFromDb = context.vwClinicMaintenances.ToList();
             foreach (var item in maintenancesFromDb)
             {
                 maintenances.Enqueue(item);
             }
             vwClinicMaintenance maintenanceToDelete = maintenances.Dequeue();
             DeleteMaintenance(maintenanceToDelete);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
 /// <summary>
 /// This method adds doctor to DbSet and save changes to database.
 /// </summary>
 /// <param name="doctor"></param>
 /// <returns>True if added, false if not.</returns>
 public bool CreateDoctor(vwClinicDoctor doctor)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblUser user = new tblUser
             {
                 Citizenship        = doctor.Citizenship,
                 DateOfBirth        = doctor.DateOfBirth,
                 Gender             = doctor.Gender,
                 IdentityCardNumber = doctor.IdentityCardNumber,
                 NameAndSurname     = doctor.NameAndSurname,
                 Password           = Encryption.EncryptPassword(doctor.Password),
                 Username           = doctor.Username
             };
             context.tblUsers.Add(user);
             context.SaveChanges();
             doctor.UserId = user.UserId;
             tblClinicDoctor newDoctor = new tblClinicDoctor
             {
                 BankAccountNumber = doctor.BankAccountNumber,
                 Department        = doctor.Department,
                 ResponsibleForPatientAdmission = doctor.ResponsibleForPatientAdmission,
                 Shift           = doctor.Shift,
                 SuperiorManager = doctor.SuperiorManager,
                 UniqueNumber    = doctor.UniqueNumber,
                 UserId          = doctor.UserId
             };
             context.tblClinicDoctors.Add(newDoctor);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method deletes patient from database.
 /// </summary>
 /// <param name="patient">Patient to be deleted.</param>
 /// <returns>True if deleted, false if not.</returns>
 public bool DeletePatient(vwClinicPatient patient)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicPatient patientToDelete = context.tblClinicPatients.Where(x => x.PatientId == patient.PatientId).FirstOrDefault();
             //finding user to be deleted
             tblUser userToDelete = context.tblUsers.Where(x => x.UserId == patient.UserId).FirstOrDefault();
             context.tblClinicPatients.Remove(patientToDelete);
             context.SaveChanges();
             context.tblUsers.Remove(userToDelete);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method adds manager to DbSet and save changes to database.
 /// </summary>
 /// <param name="manager">Manager to be added.</param>
 /// <returns>True if added, false if not.</returns>
 public bool CreateManager(vwClinicManager manager)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblUser user = new tblUser
             {
                 Citizenship        = manager.Citizenship,
                 DateOfBirth        = manager.DateOfBirth,
                 Gender             = manager.Gender,
                 IdentityCardNumber = manager.IdentityCardNumber,
                 NameAndSurname     = manager.NameAndSurname,
                 Password           = Encryption.EncryptPassword(manager.Password),
                 Username           = manager.Username
             };
             context.tblUsers.Add(user);
             context.SaveChanges();
             manager.UserId = user.UserId;
             tblClinicManager newManager = new tblClinicManager
             {
                 Floor = manager.Floor,
                 MaximumNumberOfSupervisedDoctors = manager.MaximumNumberOfSupervisedDoctors,
                 MinimumNumberOfSupervisedRooms   = manager.MinimumNumberOfSupervisedRooms,
                 NumberOfOmissions = 0,
                 UserId            = manager.UserId
             };
             context.tblClinicManagers.Add(newManager);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// This method deletes maintenance from database.
 /// </summary>
 /// <param name="maintenance">Maintenance to be deleted.</param>
 /// <returns>True if deleted, false if not.</returns>
 public bool DeleteMaintenance(vwClinicMaintenance maintenance)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblClinicMaintenance maintenanceToDelete = context.tblClinicMaintenances.Where(x => x.MaintenanceId == maintenance.MaintenanceId).FirstOrDefault();
             //finding user to be deleted
             tblUser userToDelete = context.tblUsers.Where(x => x.UserId == maintenance.UserId).FirstOrDefault();
             context.tblClinicMaintenances.Remove(maintenanceToDelete);
             context.SaveChanges();
             context.tblUsers.Remove(userToDelete);
             context.SaveChanges();
             DeleteFile(maintenanceToDelete);
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 20
0
 /// <summary>
 /// This method checks if three maintenance already exist in database.
 /// </summary>
 /// <returns>True id exist, false if not.</returns>
 public bool CheckIfExistThree()
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             int number = context.tblClinicMaintenances.Count();
             if (number < 3)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 /// <summary>
 /// This method adds patient to DbSet and save changes to database.
 /// </summary>
 /// <param name="patient"></param>
 /// <returns>True if added, false if not.</returns>
 public bool CreatePatient(vwClinicPatient patient)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblUser user = new tblUser
             {
                 Citizenship        = patient.Citizenship,
                 DateOfBirth        = patient.DateOfBirth,
                 Gender             = patient.Gender,
                 IdentityCardNumber = patient.IdentityCardNumber,
                 NameAndSurname     = patient.NameAndSurname,
                 Password           = Encryption.EncryptPassword(patient.Password),
                 Username           = patient.Username
             };
             context.tblUsers.Add(user);
             context.SaveChanges();
             patient.UserId = user.UserId;
             tblClinicPatient newPatient = new tblClinicPatient
             {
                 ExpirationDateOfHealthInsurance = patient.ExpirationDateOfHealthInsurance,
                 HealthInsuranceCardNumber       = patient.HealthInsuranceCardNumber,
                 UniqueNumberOfSelectedDoctor    = patient.UniqueNumberOfSelectedDoctor,
                 UserId = patient.UserId
             };
             context.tblClinicPatients.Add(newPatient);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// This method adds maintenance to DbSet and save changes to database.
 /// </summary>
 /// <param name="maintenance">maintenance to be added.</param>
 /// <returns>True if added, false if not.</returns>
 public bool CreateMaintenance(vwClinicMaintenance maintenance)
 {
     try
     {
         using (ClinicEntities context = new ClinicEntities())
         {
             tblUser user = new tblUser
             {
                 NameAndSurname     = maintenance.NameAndSurname,
                 IdentityCardNumber = maintenance.IdentityCardNumber,
                 Gender             = maintenance.Gender,
                 DateOfBirth        = maintenance.DateOfBirth.Date,
                 Citizenship        = maintenance.Citizenship,
                 Username           = maintenance.Username,
                 Password           = Encryption.EncryptPassword(maintenance.Password)
             };
             context.tblUsers.Add(user);
             context.SaveChanges();
             maintenance.UserId = user.UserId;
             tblClinicMaintenance newMaintenance = new tblClinicMaintenance
             {
                 PermissionToExpandClinic = maintenance.PermissionToExpandClinic,
                 ResponsibleForAccessibilityOfInvalids = maintenance.ResponsibleForAccessibilityOfInvalids,
                 UserId = maintenance.UserId
             };
             context.tblClinicMaintenances.Add(newMaintenance);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }