using System; using System.Collections.Generic; using System.Diagnostics.Eventing.Reader; using System.Linq; using System.Management.Instrumentation; using System.Text; using System.Threading; 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 System.Windows.Shell; using System.Runtime; namespace musicschoolapp { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private async void registerButton_Click(object sender, RoutedEventArgs e) { await executeDB(usernameTextBox.Text, passwordBox.Password, true); } private async void loginButton_Click(object sender, RoutedEventArgs e) { await executeDB(usernameTextBox.Text, passwordBox.Password, false); //await DbHandlerAsync(); } //async Task DbHandlerAsync() //{ // await executeDB(usernameTextBox.Text, passwordBox.Password); //} static async Task executeDB(string login, string password, bool isreg) { musicschoolEntities1 musicschoolEntities = new musicschoolEntities1(); string[] strings = new string[] { login, password }; var isunique = from s in musicschoolEntities.User where s.username == login select s; if (string.Join("", strings) != String.Empty) { var query = from s in musicschoolEntities.User where s.username == login && s.password == password select s; if (query.Count() > 0 && !isreg) { MessageBox.Show("Авторизация успешна."); WorkingWindow workingWindow = new WorkingWindow(query.FirstOrDefault()); workingWindow.Show(); return true; } else { if (isreg && isunique.Count() == 0) { User user = new User(); user.username = login; user.password = password; musicschoolEntities.User.Add(user); musicschoolEntities.SaveChanges(); MessageBox.Show("Регистрация выполнена."); return true; } else if(isunique.Count() > 0) { MessageBox.Show("Пользователь уже существует."); return false; } MessageBox.Show("Ошибка логина или пароля."); return false; } } else MessageBox.Show("заполните все поля!"); return false; } } }