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;
using WpfApp1.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void authorizeBtn_Click(object sender, RoutedEventArgs e)
        {
            var login = loginTb.Text;
            var password = passwordTb.Password;

            var role = 0;
            var id = 0;

            var user = Helper.GetContext().Emploee;

            if(user.Select(x => x.Login).Contains(login) && user.Select(x => x.Password).Contains(password))
            {
                role = user.Where(i => i.Login == login && i.Password == password).Select(i => i.PositionID).FirstOrDefault();
                id = user.Where(i => i.Login == login && i.Password == password).Select(i => i.ID).FirstOrDefault();

                if(role == 1)
                {
                    (new AdminWindow()).Show();
                    Close();
                }
                else if(role == 2)
                {
                    (new WaiterWindow()).Show();
                    Close();
                }
                else if(role == 3)
                {
                    (new CookWindow()).Show();
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Логин/Пароль неверный");
            }
        }
    }
}
