1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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 LR1_05._04
- {
- /// <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 = ToursEntities.GetContext().Countries.ToList();
- }
- 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 == 0)
- ToursEntities.GetContext().Hotels.Add(_currentHotel);
- try
- {
- ToursEntities.GetContext().SaveChanges();
- MessageBox.Show("Информация сохранена!");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }
- private void BtnBack_Click(object sender, RoutedEventArgs e)
- {
- Manager.MainFrame.GoBack();
- }
- }
- }
|