using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace KarpovTur { /// /// Логика взаимодействия для AddEditPage.xaml /// public partial class AddEditPage : Page { private Hotel _currentHotel = new Hotel(); public AddEditPage(Hotel selectedHotel) { InitializeComponent(); if (selectedHotel != null) _currentHotel = selectedHotel; DataContext = _currentHotel; ComboCountries.ItemsSource = KarpovTuriEntities1.GetContext().Country.ToList(); } //gfdg private void BtnSave_Click(object sender, RoutedEventArgs e) { StringBuilder errors = new StringBuilder(); if (string.IsNullOrWhiteSpace(_currentHotel.Name)) errors.AppendLine("Укажите название отеля"); if (_currentHotel.CountOfStars < 1 || _currentHotel.CountOfStars > 5) errors.AppendLine("Количество звёзд от 1 до 5"); if (_currentHotel.Country == null) errors.AppendLine("Выбирете страну"); if (errors.Length>0) { MessageBox.Show(errors.ToString()); return; } if (_currentHotel.id_hotel == 0) KarpovTuriEntities1.GetContext().Hotel.Add(_currentHotel); try { KarpovTuriEntities1.GetContext().SaveChanges(); MessageBox.Show("Сохранено!"); Manager.MainFrame.GoBack(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } }