AppForKidsDesktop/AppForKids/Registration.axaml.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2024-12-26 07:39:55 +00:00
using System.Globalization;
using System.IO;
using System.Linq;
using AppForKids.models;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace AppForKids;
public partial class Registration : Window
{
public Registration()
{
InitializeComponent();
}
private void RegisterClick_OnClick(object? sender, RoutedEventArgs e)
{
if(string.IsNullOrEmpty(LoginTextBox.Text)) return;
if(string.IsNullOrEmpty(PasswordTextBox.Text)) return;
using var dbContext = new KidsAppDbContext();
var user = new User {
Clicks = 0,
Name = LoginTextBox.Text,
Password = PasswordTextBox.Text };
dbContext.Users.Add(user);
if (dbContext.SaveChanges() > 0)
{
new MainWindow(user).Show();
Close();
}
}
private void LoginClick_OnClick(object? sender, RoutedEventArgs e)
{
using var dbContext = new KidsAppDbContext();
if(string.IsNullOrEmpty(LoginTextBox.Text)) return;
if(string.IsNullOrEmpty(PasswordTextBox.Text)) return;
var user = dbContext.Users.FirstOrDefault(it => it.Name == LoginTextBox.Text);
if(user == null) return;
if (user.Password != PasswordTextBox.Text) return;
new MainWindow(user).Show();
Close();
}
}