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 ПодготовкаКДемо1.Pages
{
    /// <summary>
    /// Логика взаимодействия для TableHotelPage.xaml
    /// </summary>
    public partial class TableHotelPage : Page
    {
        public TableHotelPage()
        {
            InitializeComponent();
            DataGridHotel.ItemsSource = Hotel.GetHotels();
        }

        private void btnChange_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            int i = Convert.ToInt32(button.Uid);
            Hotel hotel = BaseConnect.BaseModel.Hotel.FirstOrDefault(x=>x.Id==i);
            AddHotelWindow addHotelWindow = new AddHotelWindow(hotel);
            if ((bool)addHotelWindow.ShowDialog())
            {

            }
        }

        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            string s = "";
            foreach (Hotel hotel in DataGridHotel.SelectedItems)
            {
                s += "\n" + hotel.Name;
                BaseConnect.BaseModel.Hotel.Remove(hotel);
                BaseConnect.BaseModel.SaveChanges();
            }
            MessageBox.Show("Были удалены:"+s);
            DataGridHotel.ItemsSource = Hotel.GetHotels();
        }
    }
}
