pgUpdateHotel.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfApp1
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для pgUpdateHotel.xaml
  19. /// </summary>
  20. public partial class pgUpdateHotel : Page
  21. {
  22. Hotel hotel;
  23. public pgUpdateHotel(int id)
  24. {
  25. InitializeComponent();
  26. hotel = BaseConnect.BaseModel.Hotel.FirstOrDefault(x => x.Id == id);
  27. DataContext = hotel;
  28. Country country = BaseConnect.BaseModel.Country.FirstOrDefault(x => x.Code == hotel.CountryCode);
  29. List<Country> countryList = BaseConnect.BaseModel.Country.Where(x => x.Code != hotel.CountryCode).ToList();
  30. countryList.Insert(0, country);
  31. cbCountry.ItemsSource = countryList;
  32. cbCountry.SelectedValuePath = "Code";
  33. cbCountry.DisplayMemberPath = "Name";
  34. cbCountry.SelectedIndex = 0;
  35. }
  36. private void btnSave_Click(object sender, RoutedEventArgs e)
  37. {
  38. try
  39. {
  40. if (Convert.ToInt32(tbStars.Text) <= 5 && Convert.ToInt32(tbStars.Text) >= 0)
  41. BaseConnect.BaseModel.SaveChanges();
  42. else
  43. MessageBox.Show("sasa");
  44. }
  45. catch
  46. {
  47. MessageBox.Show("sasa");
  48. }
  49. }
  50. private void cbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
  51. {
  52. hotel.CountryCode = (string)cbCountry.SelectedValue;
  53. }
  54. }
  55. }