using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace Hotel_Course_Project
{
    /// <summary>
    /// Логика взаимодействия для ClientAddOnOrderWindow.xaml
    /// </summary>
    public partial class ClientAddOnOrderWindow : Window
    {
        public ClientAddOnOrderWindow()
        {
            InitializeComponent();
            ClientList.ItemsSource = DataBase.db.Client.Where(item => item.Id_PersStatus == 1).ToList();
        }

        private void ClientSeacrhTB_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (ClientSeacrhTB.Text == "")
            {
                ClientList.ItemsSource = DataBase.db.Client.Where(item => item.Id_PersStatus == 1).ToList();
            }
        }

        private void ClientSrchBtn_Click(object sender, RoutedEventArgs e)
        {
            var seacrhed = DataBase.db.Client.Where(item => (item.LName + " " + item.FName + " " + item.MName).Contains(ClientSeacrhTB.Text)).ToList();
            ClientList.ItemsSource = seacrhed.Where(item => item.Id_PersStatus == 1).ToList();
        }

        private void ClientSelectBtn_Click(object sender, RoutedEventArgs e)
        {
            Client client = (sender as Button).DataContext as Client;
            Helper.SelectedClientOnOrder = client;
            DialogResult = true;
        }

        private void BackBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
