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 UP_Session1_Belov.Pages
{
    /// <summary>
    /// Логика взаимодействия для LoginPage.xaml
    /// </summary>
    public partial class LoginPage : Page
    {
        public LoginPage()
        {
            InitializeComponent();
        }

        private void LogIn_Click(object sender, RoutedEventArgs e)
        {
            if (loginText.Text.Length > 0 && passwordText.Password.Length > 0)
            {
                using (UP_41P_BelovRAEntities db = new UP_41P_BelovRAEntities())
                {
                    User client = db.User.FirstOrDefault(x => x.UserLogin == loginText.Text && x.UserPassword == passwordText.Password);
                    if (client != null)
                    {                       
                        GlobalVariables.idUser = client.UserID;

                        GlobalVariables.frame.Navigate(new ProductListPage());
                    }
                    else
                    {
                        MessageBox.Show("Неверные логин или пароль");
                    }
                }
            }
            else
            {
                MessageBox.Show("Поля не должны быть пустыми");
            }
        }

        private void EnterLikeGuest_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
