public void TenDeleteTenant(object sender, RoutedEventArgs e)
        {
            EditingTenant = (LokaVerkefniCL.Tenant)TenantDisplayComboboxNameList.SelectedItem;
            bool ApartmentInRent = false;

            foreach (Contract a in DContext.Contracts)
            {
                if (a.ApartmentID == EditingTenant.ID)
                {
                    ApartmentInRent = true;
                }
            }

            if (ApartmentInRent)
            {
                MessageBox.Show("Leigjandin er með Íbúð í leigu og ekki hægt að Eyða");
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Ertu Viss um að þú Viljir Eyða Leigjandanum?", "Staðfesting", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                }
                else if (result == MessageBoxResult.Yes)
                {
                    LokaVerkefniCL.Tenant temp = (LokaVerkefniCL.Tenant)TenantDisplayComboboxNameList.SelectedItem;
                    DContext.context.Tenants.Remove(temp);
                }
            }
        }
 private void TenNewReference(LokaVerkefniCL.Tenant ten)
 {
     foreach (LokaVerkefniCL.Reference refe in ten.References)
     {
         refe.PersonID = ten.ID;
         DContext.context.References.AddOrUpdate(r => new { r.Description, r.PersonID }, refe);
     }
     DContext.context.SaveChanges();
 }
 private void TenEdBtnClkAddReference(object sender, RoutedEventArgs e)
 {
     LokaVerkefniCL.Reference refe = new LokaVerkefniCL.Reference(EditingTenant.ID);
     DContext.context.References.Add(refe);
     DContext.context.SaveChanges();
     DContext.context.Tenants.Load();
     DContext.context.References.Load();
     LokaVerkefniCL.Tenant Temp = (LokaVerkefniCL.Tenant)TenantDisplayComboboxNameList.SelectedItem;
     EditingTenant.References = Temp.References;
 }
 private void TenBtnClkEdit(object sender, RoutedEventArgs e)
 {
     EditingTenant               = new LokaVerkefniCL.Tenant((LokaVerkefniCL.Tenant)TenantDisplayComboboxNameList.SelectedItem);
     TenantEdit.DataContext      = EditingTenant;
     TenEdComboZip.DataContext   = ZipViewSource;
     TenEdComboZip.SelectedIndex = EditingTenant.Address.ZipID - 1;
     TenantDisplay.Visibility    = Visibility.Collapsed;
     TenantEdit.Visibility       = Visibility.Visible;
     TenantNew.Visibility        = Visibility.Collapsed;
 }
 private void TenBtnClkNew(object sender, RoutedEventArgs e)
 {
     NewTenant                  = new LokaVerkefniCL.Tenant();
     NewAddress                 = new LokaVerkefniCL.Address();
     NewTenant.Address          = NewAddress;
     TenantNew.DataContext      = NewTenant;
     TenNewComboZip.DataContext = ZipViewSource;
     TenantDisplay.Visibility   = Visibility.Collapsed;
     TenantEdit.Visibility      = Visibility.Collapsed;
     TenantNew.Visibility       = Visibility.Visible;
 }
 private void ContractNewBtnSave_Click(object sender, RoutedEventArgs e)
 {
     ContractApartment    = (LokaVerkefniCL.Apartment)ContractNewComboBoxApartment.SelectedItem;
     Contract.ApartmentID = ContractApartment.ID;
     ContractTenant       = (LokaVerkefniCL.Tenant)ContractNewComboBoxTenant.SelectedItem;
     Contract.PersonID    = ContractTenant.ID;
     DContext.context.Contracts.AddOrUpdate(c => new { c.PersonID, c.ApartmentID }, Contract);
     DContext.context.SaveChanges();
     ContractNew.Visibility  = Visibility.Collapsed;
     ContractMain.Visibility = Visibility.Visible;
 }
        private void ReferenceCheck(object sender, RoutedEventArgs e)
        {
            if (TenantDisplayComboboxNameList.SelectedIndex != -1)
            {
                LokaVerkefniCL.Tenant test = (LokaVerkefniCL.Tenant)TenantDisplayComboboxNameList.SelectedItem;

                if (test.HasReference)
                {
                    TenantDisplayComboboxReference.Visibility = Visibility.Visible;
                    TenLblReference.Visibility = Visibility.Visible;
                    TenantDisplayComboboxReference.SelectedIndex = 0;
                }

                else
                {
                    TenLblReference.Visibility = Visibility.Collapsed;
                    TenantDisplayComboboxReference.Visibility = Visibility.Collapsed;
                }
            }
        }