diff --git a/IposiGospodDemo/App.axaml b/IposiGospodDemo/App.axaml
index c088de3..48c9951 100644
--- a/IposiGospodDemo/App.axaml
+++ b/IposiGospodDemo/App.axaml
@@ -16,5 +16,6 @@
+
\ No newline at end of file
diff --git a/IposiGospodDemo/Dtos/SponsorshipOverViewCharityDto.cs b/IposiGospodDemo/Dtos/SponsorshipOverViewCharityDto.cs
new file mode 100644
index 0000000..b2ac5d4
--- /dev/null
+++ b/IposiGospodDemo/Dtos/SponsorshipOverViewCharityDto.cs
@@ -0,0 +1,8 @@
+namespace IposiGospodDemo.Dtos;
+
+public class SponsorshipOverViewCharityDto
+{
+ public string CharityName { get; set; }
+ public string? CharityLogo { get; set; }
+ public decimal SponsorshipAmount { get; set; }
+}
\ No newline at end of file
diff --git a/IposiGospodDemo/IposiGospodDemo.csproj b/IposiGospodDemo/IposiGospodDemo.csproj
index 64e6422..44a5b67 100644
--- a/IposiGospodDemo/IposiGospodDemo.csproj
+++ b/IposiGospodDemo/IposiGospodDemo.csproj
@@ -14,6 +14,7 @@
+
diff --git a/IposiGospodDemo/Session.cs b/IposiGospodDemo/Session.cs
index 668bb9d..c11fda4 100644
--- a/IposiGospodDemo/Session.cs
+++ b/IposiGospodDemo/Session.cs
@@ -1,4 +1,5 @@
using System;
+using System.Runtime.CompilerServices;
using IposiGospodDemo.Context;
namespace IposiGospodDemo;
@@ -11,7 +12,9 @@ public static class Session
public static readonly String Data = "Вторник 1 апреля 2025";
public static String RemainingTime = CalculateRemaningTime();
public static string AssetsPath = null!;
+
public static User User = null;
+ public static Runner Runner = null;
public static String CalculateRemaningTime()
{
@@ -20,4 +23,10 @@ public static class Session
? $"{timeLeft.Days} д. {timeLeft.Hours} ч. {timeLeft.Minutes} мин. до старта марафона"
: "Марафон уже начался!";
}
+
+ public static void Logout()
+ {
+ User = null;
+ Runner = null;
+ }
}
\ No newline at end of file
diff --git a/IposiGospodDemo/ViewModels/MySponsorshipWindowViewModel.cs b/IposiGospodDemo/ViewModels/MySponsorshipWindowViewModel.cs
index a87b290..9009c67 100644
--- a/IposiGospodDemo/ViewModels/MySponsorshipWindowViewModel.cs
+++ b/IposiGospodDemo/ViewModels/MySponsorshipWindowViewModel.cs
@@ -1,5 +1,11 @@
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using IposiGospodDemo.Context;
+using IposiGospodDemo.Helpers;
+using Microsoft.EntityFrameworkCore;
+using Npgsql;
using ReactiveUI;
namespace IposiGospodDemo.ViewModels;
@@ -7,16 +13,34 @@ namespace IposiGospodDemo.ViewModels;
public class MySponsorshipWindowViewModel : ViewModelBase
{
- private ObservableCollection _registrations;
+ private ObservableCollection _sponsorships;
- public ObservableCollection Registrations
+ public ObservableCollection Sponsorships
{
- get => _registrations;
- set => this.RaiseAndSetIfChanged(ref _registrations, value);
+ get => _sponsorships;
+ set => this.RaiseAndSetIfChanged(ref _sponsorships, value);
}
+
+ public Charity RunnerCharity { get; set; }
+
+ public decimal TotalAmount { get; set; }
public MySponsorshipWindowViewModel()
{
+ Sponsorships = new(DbHelper.Database.Sponsorships
+ .Include(s => s.Registration)
+ .Where(s => s.Registration.RunnerId == Session.Runner.RunnerId).ToList());
+
+ TotalAmount = Sponsorships?.Sum(s => s.Amount) ?? 0;
+ List regs = new (DbHelper.Database.Registrations.Where(r => r.RunnerId == Session.Runner.RunnerId));
+ Console.WriteLine(regs.Count);
+ Console.WriteLine(regs);
+ var registration = DbHelper.Database.Registrations
+ .Include(r => r.Charity) // Убедитесь, что Charity загружается
+ .FirstOrDefault(r => r.RunnerId == Session.Runner.RunnerId);
+
+ RunnerCharity = registration?.Charity; // Предотвращаем NullReferenceException
+ Console.WriteLine("Runner Charity = " + RunnerCharity.CharityName);
}
}
\ No newline at end of file
diff --git a/IposiGospodDemo/ViewModels/SponsorshipOverviewWindowViewModel.cs b/IposiGospodDemo/ViewModels/SponsorshipOverviewWindowViewModel.cs
new file mode 100644
index 0000000..e86be52
--- /dev/null
+++ b/IposiGospodDemo/ViewModels/SponsorshipOverviewWindowViewModel.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using IposiGospodDemo.Dtos;
+using IposiGospodDemo.Helpers;
+using ReactiveUI;
+
+namespace IposiGospodDemo.ViewModels;
+
+public class SponsorshipOverviewWindowViewModel : ViewModelBase
+{
+ private ObservableCollection _charities;
+ public ObservableCollection Charities
+ {
+ get => _charities;
+ set => this.RaiseAndSetIfChanged(ref _charities, value);
+ }
+
+ private decimal _charitiesSum;
+
+ public decimal CharitiesSum
+ {
+ get => _charitiesSum;
+ set => this.RaiseAndSetIfChanged(ref _charitiesSum, value);
+ }
+
+ public SponsorshipOverviewWindowViewModel()
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ Charities = new(DbHelper.Database.Charities
+ .Select(c => new SponsorshipOverViewCharityDto
+ {
+ CharityName = c.CharityName,
+ CharityLogo = c.CharityLogo,
+ SponsorshipAmount = c.Registrations
+ .SelectMany(r => r.Sponsorships)
+ .Sum(s => s.Amount)
+ })
+ .ToList());
+ CharitiesSum = Charities.Sum(c => c.SponsorshipAmount);
+ Console.WriteLine(Charities.Count);
+ }
+}
\ No newline at end of file
diff --git a/IposiGospodDemo/Views/AdministratorMenuWindow.axaml.cs b/IposiGospodDemo/Views/AdministratorMenuWindow.axaml.cs
index 67e4d44..beea520 100644
--- a/IposiGospodDemo/Views/AdministratorMenuWindow.axaml.cs
+++ b/IposiGospodDemo/Views/AdministratorMenuWindow.axaml.cs
@@ -20,7 +20,7 @@ public partial class AdministratorMenuWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
- Session.User = null;
+ Session.Logout();
new MainWindow().Show();
Close();
}
diff --git a/IposiGospodDemo/Views/CharityInfoWindow.axaml b/IposiGospodDemo/Views/CharityInfoWindow.axaml
index 9df6902..3d64e6d 100644
--- a/IposiGospodDemo/Views/CharityInfoWindow.axaml
+++ b/IposiGospodDemo/Views/CharityInfoWindow.axaml
@@ -13,7 +13,7 @@
-
+
diff --git a/IposiGospodDemo/Views/CoordinatorMenuWindow.axaml b/IposiGospodDemo/Views/CoordinatorMenuWindow.axaml
index 5b6d784..827408d 100644
--- a/IposiGospodDemo/Views/CoordinatorMenuWindow.axaml
+++ b/IposiGospodDemo/Views/CoordinatorMenuWindow.axaml
@@ -20,9 +20,22 @@
-
-
-
+
+
+
+
+
+
+
-
diff --git a/IposiGospodDemo/Views/LoginWindow.axaml.cs b/IposiGospodDemo/Views/LoginWindow.axaml.cs
index b193666..fcc8ba3 100644
--- a/IposiGospodDemo/Views/LoginWindow.axaml.cs
+++ b/IposiGospodDemo/Views/LoginWindow.axaml.cs
@@ -32,10 +32,11 @@ public partial class LoginWindow : Window
PasswordBox.Text != null && u.Password == PasswordBox.Text.Trim());
Session.User = user;
- Console.WriteLine("USERROLEID: " + user.Role.RoleId.ToString());
+
switch (user.Role.RoleId)
{
case 'R':
+ Session.Runner = DbHelper.Database.Runners.Single(r => r.EmailNavigation.Email == user.Email);
new RunnerMenuWindow().Show();
break;
case 'C':
@@ -46,35 +47,6 @@ public partial class LoginWindow : Window
break;
}
Close();
- // try
- // {
- // User user = DbHelper.Database.Users
- // .Include(u => u.Role)
- // .Single(u =>
- // EmailBox.Text != null && u.Email == EmailBox.Text.Trim() &&
- // PasswordBox.Text != null && u.Password == PasswordBox.Text.Trim());
- //
- // Session.User = user;
- // Console.WriteLine("USERROLEID: " + user.Role.RoleId.ToString());
- // switch (user.Role.RoleId)
- // {
- // case 'R':
- // new RunnerMenuWindow().Show();
- // break;
- // case 'C':
- // new CoordinatorMenuWindow().Show();
- // break;
- // case 'A':
- // new AdministratorMenuWindow().Show();
- // break;
- // }
- // Close();
- // }
- // catch (Exception exception)
- // {
- // Console.WriteLine("Unlucky");
- // Console.WriteLine(exception.Message);
- // }
}
private void Cancel_OnClick(object? sender, RoutedEventArgs e)
diff --git a/IposiGospodDemo/Views/MyResultsWindow.axaml.cs b/IposiGospodDemo/Views/MyResultsWindow.axaml.cs
index 34802c4..e4b8fae 100644
--- a/IposiGospodDemo/Views/MyResultsWindow.axaml.cs
+++ b/IposiGospodDemo/Views/MyResultsWindow.axaml.cs
@@ -20,7 +20,7 @@ public partial class MyResultsWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
- Session.User = null;
+ Session.Logout();
new MainWindow().Show();
Close();
}
diff --git a/IposiGospodDemo/Views/MySponsorshipWindow.axaml b/IposiGospodDemo/Views/MySponsorshipWindow.axaml
index 8f9adec..5cf63e2 100644
--- a/IposiGospodDemo/Views/MySponsorshipWindow.axaml
+++ b/IposiGospodDemo/Views/MySponsorshipWindow.axaml
@@ -2,38 +2,85 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:vm="using:IposiGospodDemo.ViewModels"
xmlns:local="using:IposiGospodDemo"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="IposiGospodDemo.Views.MySponsorshipWindow"
- Title="MySponsorshipWindow">
+ x:DataType="vm:MySponsorshipWindowViewModel"
+ Title="MySponsorshipWindow" Padding="10">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/IposiGospodDemo/Views/MySponsorshipWindow.axaml.cs b/IposiGospodDemo/Views/MySponsorshipWindow.axaml.cs
index 58401bd..288b518 100644
--- a/IposiGospodDemo/Views/MySponsorshipWindow.axaml.cs
+++ b/IposiGospodDemo/Views/MySponsorshipWindow.axaml.cs
@@ -2,6 +2,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
+using IposiGospodDemo.ViewModels;
namespace IposiGospodDemo.Views;
@@ -10,6 +11,7 @@ public partial class MySponsorshipWindow : Window
public MySponsorshipWindow()
{
InitializeComponent();
+ DataContext = new MySponsorshipWindowViewModel();
}
private void GoBack_OnClick(object? sender, RoutedEventArgs e)
@@ -20,7 +22,7 @@ public partial class MySponsorshipWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
- Session.User = null;
+ Session.Logout();
new MainWindow().Show();
Close();
}
diff --git a/IposiGospodDemo/Views/RegistrationForAnEventWindow.axaml.cs b/IposiGospodDemo/Views/RegistrationForAnEventWindow.axaml.cs
index 425cb87..7e3fade 100644
--- a/IposiGospodDemo/Views/RegistrationForAnEventWindow.axaml.cs
+++ b/IposiGospodDemo/Views/RegistrationForAnEventWindow.axaml.cs
@@ -20,7 +20,7 @@ public partial class RegistrationForAnEventWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
- Session.User = null;
+ Session.Logout();
new MainWindow().Show();
Close();
}
diff --git a/IposiGospodDemo/Views/RunnerMenuWindow.axaml.cs b/IposiGospodDemo/Views/RunnerMenuWindow.axaml.cs
index 7d30982..71b58e7 100644
--- a/IposiGospodDemo/Views/RunnerMenuWindow.axaml.cs
+++ b/IposiGospodDemo/Views/RunnerMenuWindow.axaml.cs
@@ -20,7 +20,7 @@ public partial class RunnerMenuWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
- Session.User = null;
+ Session.Logout();
new MainWindow().Show();
Close();
}
diff --git a/IposiGospodDemo/Views/SponsorARunnerWindow.axaml.cs b/IposiGospodDemo/Views/SponsorARunnerWindow.axaml.cs
index 12ec786..24faeec 100644
--- a/IposiGospodDemo/Views/SponsorARunnerWindow.axaml.cs
+++ b/IposiGospodDemo/Views/SponsorARunnerWindow.axaml.cs
@@ -88,6 +88,7 @@ public partial class SponsorARunnerWindow : Window
newSponsorship.Registration = _viewModel.SelectedRunner.Registrations.FirstOrDefault()!;
newSponsorship.Amount = _viewModel.Sum;
DbHelper.Database.Sponsorships.Add(newSponsorship);
+ DbHelper.Database.SaveChanges();
new SponsorshipConfirmationWindow(_viewModel.SelectedRunner.EmailNavigation, _viewModel.Sum, _viewModel.SelectedCharity.CharityName).Show();
Close();
diff --git a/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml b/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml
new file mode 100644
index 0000000..33566c8
--- /dev/null
+++ b/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml.cs b/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml.cs
new file mode 100644
index 0000000..4e6afab
--- /dev/null
+++ b/IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml.cs
@@ -0,0 +1,29 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+using IposiGospodDemo.ViewModels;
+
+namespace IposiGospodDemo.Views;
+
+public partial class SponsorshipOverviewWindow : Window
+{
+ public SponsorshipOverviewWindow()
+ {
+ InitializeComponent();
+ DataContext = new SponsorshipOverviewWindowViewModel();
+ }
+
+ private void GoBack_OnClick(object? sender, RoutedEventArgs e)
+ {
+ new CoordinatorMenuWindow().Show();
+ Close();
+ }
+
+ private void Logout_OnClick(object? sender, RoutedEventArgs e)
+ {
+ Session.Logout();
+ new MainWindow().Show();
+ Close();
+ }
+}
\ No newline at end of file