internal void EditAdopter(AdopterWithAdress editAdopter, ObservableCollection <AdopterWithAdress> adoptersWithAdress) { // Find the same object in DB var adopterFromDb = GetAdopterById(editAdopter.IdAdopter); var adopterFromView = adoptersWithAdress.FirstOrDefault(x => x.IdAdopter == editAdopter.IdAdopter); // change properties in DB object adopterFromDb.Name = editAdopter.Name; adopterFromDb.Surname = editAdopter.Surname; adopterFromDb.PhoneNumber = editAdopter.PhoneNumber; adopterFromDb.Street = editAdopter.Street; adopterFromDb.HouseNumber = editAdopter.HouseNumber; adopterFromDb.IdAdress = editAdopter.IdAdress; // change properties in ObservableColletion for View adopterFromView.Name = editAdopter.Name; adopterFromView.Surname = editAdopter.Surname; adopterFromView.PhoneNumber = editAdopter.PhoneNumber; adopterFromView.Street = editAdopter.Street; adopterFromView.HouseNumber = editAdopter.HouseNumber; adopterFromView.IdAdress = editAdopter.IdAdress; adopterFromView.City = editAdopter.City; adopterFromView.PostCode = editAdopter.PostCode; _context.SaveChanges(); MessageBox.Show("Pomyślnie zmieniłem dane."); }
public AdopterEdit(AdopterWithAdress adopterToEdit, ObservableCollection <AdopterWithAdress> adoptersWithAdress) { this.adopterToEdit = adopterToEdit; this.adoptersWithAdress = adoptersWithAdress; var getAdresses = new ObservableCollection <Adress>(viewmodel.GetAdresses()); this.addresses = getAdresses; this.addressesWithoutFilter = new ObservableCollection <Adress>(addresses); InitializeComponent(); TextBoxName.Text = adopterToEdit.Name; TextBoxSurname.Text = adopterToEdit.Surname; TextBoxPhone.Text = adopterToEdit.PhoneNumber; TextBoxStreet.Text = adopterToEdit.Street; TextBoxHouseNumber.Text = adopterToEdit.HouseNumber; DataGridCity.ItemsSource = viewmodel.GetAdresses(); DataGridCity.SelectedItem = viewmodel.GetAdressById(adopterToEdit.IdAdress); DataGridCity.ScrollIntoView(DataGridCity.Items[DataGridCity.Items.Count - 1]); DataGridCity.ScrollIntoView(DataGridCity.SelectedItem); }