private void TenEdBtnClkSave(object sender, RoutedEventArgs e)
        {
            Post = (LokaVerkefniCL.Zip)TenEdComboZip.SelectedItem;
            EditingTenant.Address.ZipID = Post.ID;
            DContext.context.Adresses.AddOrUpdate(a => a.ID, EditingTenant.Address);
            DContext.context.Tenants.AddOrUpdate(t => t.AddressID, EditingTenant);
            TenantDisplay.Visibility = Visibility.Visible;
            TenantEdit.Visibility    = Visibility.Collapsed;
            int sel = TenantDisplayComboboxNameList.SelectedIndex;

            TenantDisplayComboboxNameList.SelectedIndex = -1;
            TenantDisplayComboboxNameList.SelectedIndex = sel;
        }
 /// <summary>
 /// Saving the New Apartment and Adress to Database
 /// </summary>
 private void AptAddAptment(object sender, RoutedEventArgs e)
 {
     // geting the selected zip code into a transitional variable to access its ID
     Post = (LokaVerkefniCL.Zip)ApartmentNewApartmentComboBoxZip.SelectedItem;
     // taking the zip id from transitional variable and setting it to NewAddress
     NewAddress.ZipID = Post.ID;
     // adding the new adress to database and checking if it exists to get its adress ID
     DContext.context.Adresses.AddOrUpdate(a => a.AdressKey, NewAddress);
     DContext.context.SaveChanges();
     // taking the adress ID obtained from Database and giving it to NewApartment
     NewApartment.AddressID = NewAddress.ID;
     // adding the new Apartment to Database, if Current Adress already has an
     // apartment registered updates that instead
     DContext.context.Apartments.AddOrUpdate(a => a.AddressID, NewApartment);
     DContext.context.SaveChanges();
     // Hiding the New Apartment Grid and showing the Display Grid
     ApartmentDisplay.Visibility      = Visibility.Visible;
     ApartmentNewApartment.Visibility = Visibility.Collapsed;
 }
        private void AptSaveChanges(object sender, RoutedEventArgs e)
        {
            // geting the selected zip code into a transitional variable to access its ID
            Post = (LokaVerkefniCL.Zip)ApartmentEditComboBoxZip.SelectedItem;
            // taking the zip id from transitional variable and setting it to the edited Address
            EditingApartment.Address.ZipID = Post.ID;
            // updating the adress in the database
            DContext.context.Adresses.AddOrUpdate(a => a.ID, EditingApartment.Address);
            // updating the apartment in the database
            DContext.context.Apartments.AddOrUpdate(a => a.AddressID, EditingApartment);
            DContext.context.SaveChanges();
            // Hiding the Edit Grid and showing the Display Grid
            ApartmentEdit.Visibility    = Visibility.Collapsed;
            ApartmentDisplay.Visibility = Visibility.Visible;
            // seting the combobox to select default value and then return to
            // selected value in order to force update on the display grid
            int sel = ApartmentDisplayComboBoxApartment.SelectedIndex;

            ApartmentDisplayComboBoxApartment.SelectedIndex = -1;
            ApartmentDisplayComboBoxApartment.SelectedIndex = sel;
        }