Esempio n. 1
0
 public static void AddSingleToManyRelationships(DataBaseContext context, DbMedicalWorker medicalWorker, List <DbAvailability> availabilities)
 {
     foreach (var availability in availabilities)
     {
         AddSingleRelationship(context, medicalWorker, availability);
     }
 }
 public static void AddSingleToManyRelationships(DataBaseContext context, DbMedicalWorker medicalWorkers, List <DbSpecialization> specializations)
 {
     foreach (var specialization in specializations)
     {
         AddSingleRelationship(context, medicalWorkers, specialization);
     }
 }
 public static void AddSingleRelationship(DataBaseContext context, DbMedicalWorker medicalWorker, DbSpecialization specialization)
 {
     context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id).Specializations.Add(context.Specializations.SingleOrDefault(s => s.Id == specialization.Id));
     context.Specializations.SingleOrDefault(s => s.Id == specialization.Id).MedicalWorkers.Add(context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id));
 }
Esempio n. 4
0
 public static void AddSingleRelationship(DataBaseContext context, DbMedicalWorker medicalWorker, DbAvailability availability)
 {
     context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id).Availabilities.Add(context.Availabilities.SingleOrDefault(a => a.Id == availability.Id));
     context.Availabilities.SingleOrDefault(a => a.Id == availability.Id).MedicalWorker = context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id);
 }
Esempio n. 5
0
 private static void AddSingleRelationship(DataBaseContext context, DbVisit visit, DbMedicalWorker medicalWorker)
 {
     context.Visits.SingleOrDefault(v => v.Id == visit.Id).MedicalWorker = context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id);
     context.MedicalWorkers.SingleOrDefault(mw => mw.Id == medicalWorker.Id).Visits.Add(context.Visits.SingleOrDefault(v => v.Id == visit.Id));
 }
Esempio n. 6
0
 public static void AddSingleCompleteRelationships(DataBaseContext context, DbVisit visit, DbMedicalWorker medicalWorker, DbPatient patient, DbSpecialization specialization)
 {
     if (!medicalWorker.Specializations.Contains(context.Specializations.SingleOrDefault(x => x.Id == specialization.Id)))
     {
         throw new Exception("In function AddSingleCompleteRelationships medicalWorker doesn't have required specialization");
     }
     AddSingleRelationship(context, visit, medicalWorker);
     AddSingleRelationship(context, visit, patient);
     AddSingleRelationship(context, visit, specialization);
 }
Esempio n. 7
0
        private void SaveNewUserButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (LoginTextBox.Text == "" || PasswordTextBox.Password == "")
                {
                    throw new Exception("Name and surname must be provided!");
                }
                if (UserList.Exists(x => x.Username == LoginTextBox.Text))
                {
                    throw new Exception("User already exists!");
                }
                if (AccessLevelChoiceComboBox.SelectedIndex == -1)
                {
                    throw new Exception("You need to select access level!");
                }

                UserAccess newUserAccess = UserAccess.Admin;

                var index = AccessLevelChoiceComboBox.SelectedIndex;
                if (index != -1)
                {
                    switch (index)
                    {
                    case 0:
                        newUserAccess = UserAccess.Admin;
                        break;

                    case 1:
                        newUserAccess = UserAccess.Recepcjonista;
                        break;

                    case 2:
                        newUserAccess = UserAccess.PracownikMedyczny;
                        break;

                    default:
                        break;
                    }

                    using (var context = new DataBaseContext())
                    {
                        if (newUserAccess == UserAccess.PracownikMedyczny)
                        {
                            if (FirstNameTextBox.Text == "" || LastNameTextBox.Text == "")
                            {
                                throw new Exception("Name and surname must be provided!");
                            }

                            var NewMedicalWorker = new DbMedicalWorker()
                            {
                                FirstName       = FirstNameTextBox.Text,
                                LastName        = LastNameTextBox.Text,
                                Availabilities  = new List <DbAvailability>(),
                                Specializations = new List <DbSpecialization>(),
                                Visits          = new List <DbVisit>()
                            };
                            context.MedicalWorkers.Add(NewMedicalWorker);
                            context.SaveChanges();

                            context.Users.Add(new DbUser()
                            {
                                Login         = LoginTextBox.Text,
                                Password      = PasswordTextBox.Password,
                                UserAccess    = newUserAccess,
                                MedicalWorker = NewMedicalWorker
                            });
                            context.SaveChanges();
                        }
                        else
                        {
                            context.Users.Add(new DbUser()
                            {
                                Login      = LoginTextBox.Text,
                                Password   = PasswordTextBox.Password,
                                UserAccess = newUserAccess
                            });
                            context.SaveChanges();
                        }
                    }
                    UserList = UserForUsersManagementTab.GetRepresentation();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }