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 KinoPoisk
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void CreateAcc_Click(object sender, RoutedEventArgs e)
        {
            RegistrationWindow registrationWindow = new RegistrationWindow();
            this.Close();
            registrationWindow.Show();
        }

        private void SignIn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                KinoPoiskContext context = new KinoPoiskContext();
                var users = context.Users;
                User user = users.SingleOrDefault(x => x.PhoneNumber == PhoneNumber.Text && x.UserPassword == Password.Password);
                if (user == null)
                {
                    MessageBox.Show("Пользователь не найден!");
                }
                else
                {
                    UserData.Id = user.Id;
                    UserData.FirstName = user.FirstName;
                    UserData.LastName = user.LastName;
                    UserData.PhoneNumber = user.PhoneNumber;
                    UserData.UserPassword = user.UserPassword;
                    UserData.Status = Convert.ToInt32(user.Status);

                    MessageBox.Show("Вы успешно зашли в Аккаунт!");

                    MainMenu mainMenu = new MainMenu();
                    this.Close();
                    mainMenu.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка! {ex}");
                throw;
            }   
        }
    }
}
