public ToursPage()
        {
            InitializeComponent();
            var CurrelTours = ToursBaseEntities1.GetContext().Tour.ToList();

            LViewTours.ItemsSource = CurrelTours;
        }
 private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (Visibility == Visibility.Visible)
     {
         ToursBaseEntities1.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload());
         DGridHotels.ItemsSource = ToursBaseEntities1.GetContext().Hotel.ToList();
     }
 }
Exemplo n.º 3
0
        public static ToursBaseEntities1 GetContext()
        {
            if (_context == null)
            {
                _context = new ToursBaseEntities1();
            }

            return(_context);
        }
        public AddEditPage(Hotel selectedHotel)
        {
            InitializeComponent();

            if (selectedHotel != null)
            {
                _correntHotel = selectedHotel;
            }

            ComboCountry.ItemsSource = ToursBaseEntities1.GetContext().Country.ToList();
            DataContext = _correntHotel;
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var hotelfotRemove = DGridHotels.SelectedItems.Cast <Hotel>().ToList();

            if (MessageBox.Show($" Вы точно хотите удалить {hotelfotRemove.Count()} Элементов ?", " Внимание ",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    ToursBaseEntities1.GetContext().Hotel.RemoveRange(hotelfotRemove);
                    ToursBaseEntities1.GetContext().SaveChanges();
                    MessageBox.Show("Данные удалены");
                    DGridHotels.ItemsSource = ToursBaseEntities1.GetContext().Hotel.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            StringBuilder errors = new StringBuilder();

            if (string.IsNullOrWhiteSpace(_correntHotel.Name))
            {
                errors.AppendLine("Укажите название отеля");
            }
            if (_correntHotel.CountOfStars < 1 || _correntHotel.CountOfStars > 5)
            {
                errors.AppendLine("Число звезд от 1 до 5");
            }
            if (_correntHotel.Country == null)
            {
                ToursBaseEntities1.GetContext().SaveChanges();
            }
            errors.AppendLine("Выберите страну");

            if (errors.Length > 0)
            {
                MessageBox.Show(errors.ToString());
                return;
            }

            if (_correntHotel.ID == 0)
            {
                ToursBaseEntities1.GetContext().Hotel.Add(_correntHotel);
            }

            try
            {
                ToursBaseEntities1.GetContext().SaveChanges();
                MessageBox.Show("Успешно");
                Manager.MainFrame.GoBack();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }