123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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 ToursAppKhritankov
- {
- /// <summary>
- /// Логика взаимодействия для AddEditPage.xaml
- /// </summary>
- public partial class AddEditPage : Page
- {
- private Hotel _currentHotel = new Hotel();
- public AddEditPage(Hotel selectedHotel)
- {
- InitializeComponent();
- if (selectedHotel != null)
- _currentHotel = selectedHotel;
- DataContext = _currentHotel;
- ComboCountries.ItemsSource = ToursKhritankovEntities.GetContext().Country.ToList();
- }
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- StringBuilder errors = new StringBuilder();
- if (string.IsNullOrWhiteSpace(_currentHotel.Name))
- errors.AppendLine("Укажите название отеля");
- if (_currentHotel.CountOnStars < 1 || _currentHotel.CountOnStars > 5)
- errors.AppendLine("Количество звёзд - число от 1 до 5");
- if (_currentHotel.Country == null)
- errors.AppendLine("Выберите страну");
- if (errors.Length > 0)
- {
- MessageBox.Show(errors.ToString());
- return;
- }
- if (_currentHotel.id == 0)
- ToursKhritankovEntities.GetContext().Hotel.Add(_currentHotel);
- try
- {
- ToursKhritankovEntities.GetContext().SaveChanges();
- MessageBox.Show("Информация сохранена");
- Manager.MainFrame.GoBack();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }
- }
- }
|