36 lines
952 B
C#
36 lines
952 B
C#
using AppForKids.models;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
|
|
namespace AppForKids;
|
|
|
|
public partial class MainWindow : Window
|
|
{
|
|
private User? _currentUser = null;
|
|
public MainWindow(User user)
|
|
{
|
|
_currentUser = user;
|
|
InitializeComponent();
|
|
CountClickText();
|
|
}
|
|
|
|
private void CountClickText()
|
|
{
|
|
if (_currentUser == null) return;
|
|
ClickCounts.Text = $"Click count: {_currentUser.Clicks}";
|
|
}
|
|
private void OpenScoreButton_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
if(_currentUser == null) return;
|
|
new Score().ShowDialog(this);
|
|
}
|
|
|
|
private void ImageButton_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
using var dbContext = new KidsAppDbContext();
|
|
if(_currentUser == null) return;
|
|
_currentUser.Clicks += 1;
|
|
dbContext.Update(_currentUser);
|
|
if(dbContext.SaveChanges() > 0) CountClickText();
|
|
}
|
|
} |