From 13cb67d3a657a2a0beab308e27ce4be96e68284d Mon Sep 17 00:00:00 2001 From: 1eG0ist Date: Tue, 4 Mar 2025 11:01:22 +0300 Subject: [PATCH] add more --- IposiGospodDemo/App.axaml | 1 + .../Dtos/SponsorshipOverViewCharityDto.cs | 8 ++ IposiGospodDemo/IposiGospodDemo.csproj | 1 + IposiGospodDemo/Session.cs | 9 ++ .../MySponsorshipWindowViewModel.cs | 32 +++++- .../SponsorshipOverviewWindowViewModel.cs | 47 ++++++++ .../Views/AdministratorMenuWindow.axaml.cs | 2 +- IposiGospodDemo/Views/CharityInfoWindow.axaml | 2 +- .../Views/CoordinatorMenuWindow.axaml | 19 +++- .../Views/CoordinatorMenuWindow.axaml.cs | 13 ++- .../Views/EditRunnerProfileWindow.axaml.cs | 2 +- .../Views/ListOfCharitiesWindow.axaml | 2 +- IposiGospodDemo/Views/LoginWindow.axaml.cs | 32 +----- .../Views/MyResultsWindow.axaml.cs | 2 +- .../Views/MySponsorshipWindow.axaml | 107 +++++++++++++----- .../Views/MySponsorshipWindow.axaml.cs | 4 +- .../RegistrationForAnEventWindow.axaml.cs | 2 +- .../Views/RunnerMenuWindow.axaml.cs | 2 +- .../Views/SponsorARunnerWindow.axaml.cs | 1 + .../Views/SponsorshipOverviewWindow.axaml | 75 ++++++++++++ .../Views/SponsorshipOverviewWindow.axaml.cs | 29 +++++ 21 files changed, 316 insertions(+), 76 deletions(-) create mode 100644 IposiGospodDemo/Dtos/SponsorshipOverViewCharityDto.cs create mode 100644 IposiGospodDemo/ViewModels/SponsorshipOverviewWindowViewModel.cs create mode 100644 IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml create mode 100644 IposiGospodDemo/Views/SponsorshipOverviewWindow.axaml.cs 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"> - - - -