using Exam.Pages;
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 Exam
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        users user;
        public MainWindow()
        {
            DBContext.Connect = new ExamPm01Entities();
            InitializeComponent();
        }

        private void Autorisation_Click(object sender, RoutedEventArgs e)
        {
            user = DBContext.Connect.users.FirstOrDefault(x => (x.email.ToString() == TBLogin.Text) && (x.password == TBPassword.Text));
            if (user == null) MessageBox.Show("Пользователь не найден");
            else
            {
                SPAutorisation.Visibility = Visibility.Collapsed;
                SPButtons.Visibility = Visibility.Visible;
                if (DBContext.Connect.posts.FirstOrDefault(x => x.id == user.id_post).id_role == 1)
                {
                    BRate.Visibility = Visibility.Visible;
                }
                MainFrame.Navigate(new UserActivity(user));
            }
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mw = new MainWindow();
            mw.Show();
            this.Close();
        }

        private void ToRatePage_Click(object sender, RoutedEventArgs e)
        {
            BRate.Visibility = Visibility.Collapsed;
            BMain.Visibility = Visibility.Visible;
            MainFrame.Navigate(new RatePage());
        }

        private void MainPage_Click(object sender, RoutedEventArgs e)
        {
            BRate.Visibility = Visibility.Visible;
            BMain.Visibility = Visibility.Collapsed;
            MainFrame.Navigate(new UserActivity(user));
        }
    }
}
