/// <summary> Konstruktor uruchamiany w celu dodania nowego wpisu </summary> public CityEditViewModel(string connectionString) { this.SaveButtonClick = new GalaSoft.MvvmLight.Command.RelayCommand(() => { try { if (this.PostalCodeTextBoxContent == null || this.CityNameTextBoxContent == null) { MessageBox.Show("Wypełnij pole z kodem pocztowym i nazwą"); } else { using (var ctx = new molkomEntities()) { ctx.Cities.Add(GetCityObject()); ctx.SaveChanges(); GlobalVariables.refreshMainWindowFlag = 1; RequestClose?.Invoke(this, EventArgs.Empty); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }); SetDefaultDateFormat(); }
/// <summary> Zapisanie zmian edytowanego elementu do bazy danych </summary> public void SaveEntry() { try { using (var ctx = new molkomEntities()) { var address = ctx.Addresses.FirstOrDefault(x => x.id == this.idOfEntity); if (address != null) { address.name = this.NameTextBoxContent; address.surname = this.SurnameTextBoxContent; address.phoneNumber = this.PhoneTextBoxContent; address.birthdate = new DateTime(Int32.Parse(this.YearOfBirthTextBoxContent), this.MonthOfBirthSelectedIndex + 1, Int32.Parse(this.DayOfBirthTextBoxContent)); address.status = this.Status; if (GetIdOfSelectedCityItem() != 0) { address.city = GetIdOfSelectedCityItem(); } address.dateOfUpdate = System.DateTime.Now; ctx.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> Zapisanie zmian edytowanego elementu do bazy danych </summary> public void SaveEntry() { try { using (var ctx = new molkomEntities()) { var address = ctx.Cities.FirstOrDefault(x => x.id == this.idOfEntity); if (address != null) { address.postalCode = PostalCodeTextBoxContent; address.name = CityNameTextBoxContent; address.dateOfCreation = System.DateTime.Now; address.dateOfUpdate = System.DateTime.Now; ctx.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> Konstruktor uruchamiany w celu dodania nowego wpisu </summary> public AddressEditViewModel(string connectionString) { this.SaveButtonClick = new GalaSoft.MvvmLight.Command.RelayCommand(() => { try { if (this.NameTextBoxContent == null || this.SurnameTextBoxContent == null) { MessageBox.Show("Wypełnij pole z imieniem i nazwiskiem"); } else { using (var ctx = new molkomEntities()) { ctx.Addresses.Add(GetAddressObject()); ctx.SaveChanges(); GlobalVariables.refreshMainWindowFlag = 1; RequestClose?.Invoke(this, EventArgs.Empty); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }); this.Status = true; this.DateOfCreation = System.DateTime.Now; this.DateOfUpdate = System.DateTime.Now; this.CitiesComboBoxContent = new ObservableCollection <string>(); this.MonthOfBirthComboBoxContent = new ObservableCollection <string>(); SetDefaultDateFormat(); LoadMonthsComboBoxContent(); LoadCitiesComboBoxContent(connectionString); }