From 38cf16c345620460ae7f35458594b103cab78067 Mon Sep 17 00:00:00 2001 From: Dasha06 Date: Sun, 22 Dec 2024 15:37:22 +0300 Subject: [PATCH] creating presence, not working transition to presence --- .../DI/ServiceCollictionExtensions.cs | 5 +- Presence.Desktop/Models/PresencePresenter.cs | 16 +++ Presence.Desktop/Models/UserPresenter.cs | 1 + Presence.Desktop/ViewModels/GroupViewModel.cs | 17 ++- .../ViewModels/PresenceViewModel.cs | 111 ++++++++++++++++-- Presence.Desktop/Views/GroupView.axaml | 5 + Presence.Desktop/Views/PresenceView.axaml | 34 +++++- .../bin/Debug/net8.0/Presence.Desktop.dll | Bin 224768 -> 236032 bytes .../bin/Debug/net8.0/Presence.Desktop.pdb | Bin 21856 -> 23052 bytes Presence.Desktop/bin/Debug/net8.0/data.dll | Bin 40960 -> 41472 bytes Presence.Desktop/bin/Debug/net8.0/data.pdb | Bin 20448 -> 20588 bytes Presence.Desktop/bin/Debug/net8.0/domain.dll | Bin 25088 -> 25088 bytes Presence.Desktop/bin/Debug/net8.0/domain.pdb | Bin 19204 -> 19240 bytes .../net8.0/Avalonia/Presence.Desktop.dll | Bin 224768 -> 236032 bytes .../net8.0/Avalonia/Presence.Desktop.pdb | Bin 21856 -> 23052 bytes .../obj/Debug/net8.0/Avalonia/resources | Bin 181641 -> 183167 bytes .../net8.0/Presence.Desktop.AssemblyInfo.cs | 2 +- .../Presence.Desktop.AssemblyInfoInputs.cache | 2 +- ...nce.Desktop.csproj.AssemblyReference.cache | Bin 22498 -> 22498 bytes ...nce.Desktop.csproj.CoreCompileInputs.cache | 2 +- .../obj/Debug/net8.0/Presence.Desktop.dll | Bin 202752 -> 207872 bytes .../obj/Debug/net8.0/Presence.Desktop.pdb | Bin 20120 -> 21512 bytes .../obj/Debug/net8.0/ref/Presence.Desktop.dll | Bin 10240 -> 11776 bytes .../refint/Avalonia/Presence.Desktop.dll | Bin 10240 -> 11776 bytes .../Debug/net8.0/refint/Presence.Desktop.dll | Bin 11264 -> 12800 bytes .../Debug/net8.0/console_ui.AssemblyInfo.cs | 2 +- .../console_ui.AssemblyInfoInputs.cache | 2 +- .../console_ui.csproj.AssemblyReference.cache | Bin 11349 -> 12553 bytes data/Repository/IPresenceRepository.cs | 1 + data/Repository/PresenceRepositoryImpl.cs | 13 ++ data/bin/Debug/net8.0/data.dll | Bin 40960 -> 41472 bytes data/bin/Debug/net8.0/data.pdb | Bin 20448 -> 20588 bytes data/obj/Debug/net8.0/data.AssemblyInfo.cs | 4 +- .../net8.0/data.AssemblyInfoInputs.cache | 2 +- data/obj/Debug/net8.0/data.dll | Bin 40960 -> 41472 bytes data/obj/Debug/net8.0/data.pdb | Bin 20448 -> 20588 bytes data/obj/Debug/net8.0/ref/data.dll | Bin 14848 -> 14848 bytes data/obj/Debug/net8.0/refint/data.dll | Bin 14848 -> 14848 bytes domain/UseCase/PresenceUseCase.cs | 5 + domain/bin/Debug/net8.0/data.dll | Bin 40960 -> 41472 bytes domain/bin/Debug/net8.0/data.pdb | Bin 20448 -> 20588 bytes domain/bin/Debug/net8.0/domain.dll | Bin 25088 -> 25088 bytes domain/bin/Debug/net8.0/domain.pdb | Bin 19204 -> 19240 bytes .../obj/Debug/net8.0/domain.AssemblyInfo.cs | 4 +- .../net8.0/domain.AssemblyInfoInputs.cache | 2 +- .../domain.csproj.AssemblyReference.cache | Bin 8151 -> 8151 bytes domain/obj/Debug/net8.0/domain.dll | Bin 25088 -> 25088 bytes domain/obj/Debug/net8.0/domain.pdb | Bin 19204 -> 19240 bytes domain/obj/Debug/net8.0/ref/domain.dll | Bin 13312 -> 13312 bytes domain/obj/Debug/net8.0/refint/domain.dll | Bin 13312 -> 13312 bytes .../Debug/net8.0/presence_api.AssemblyInfo.cs | 2 +- .../presence_api.AssemblyInfoInputs.cache | 2 +- ...resence_api.csproj.AssemblyReference.cache | Bin 6446 -> 5242 bytes ui/obj/Debug/net8.0/ui.AssemblyInfo.cs | 2 +- .../Debug/net8.0/ui.AssemblyInfoInputs.cache | 2 +- .../net8.0/ui.csproj.AssemblyReference.cache | Bin 10602 -> 11467 bytes 56 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 Presence.Desktop/Models/PresencePresenter.cs diff --git a/Presence.Desktop/DI/ServiceCollictionExtensions.cs b/Presence.Desktop/DI/ServiceCollictionExtensions.cs index 08b42a2..56b7cab 100644 --- a/Presence.Desktop/DI/ServiceCollictionExtensions.cs +++ b/Presence.Desktop/DI/ServiceCollictionExtensions.cs @@ -7,6 +7,7 @@ using presence.data.RemoteData.RemoteDataBase; using presence.data.Repository; using presence.domain.UseCase; using Presence.Desktop.ViewModels; +using ReactiveUI; using System; using System.Collections.Generic; using System.Linq; @@ -23,8 +24,10 @@ namespace Presence.Desktop.DI .AddDbContext() .AddSingleton() .AddSingleton() + .AddTransient() .AddTransient() - .AddTransient(); + .AddTransient() + .AddTransient(); } } } \ No newline at end of file diff --git a/Presence.Desktop/Models/PresencePresenter.cs b/Presence.Desktop/Models/PresencePresenter.cs new file mode 100644 index 0000000..337401b --- /dev/null +++ b/Presence.Desktop/Models/PresencePresenter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.Models +{ + public class PresencePresenter + { + public DateOnly Date { get; set; } + public int ClassNumber { get; set; } + public bool IsAttendence { get; set; } + public UserPresenter? User { get; set; } + } +} \ No newline at end of file diff --git a/Presence.Desktop/Models/UserPresenter.cs b/Presence.Desktop/Models/UserPresenter.cs index 45cecce..00ad6c0 100644 --- a/Presence.Desktop/Models/UserPresenter.cs +++ b/Presence.Desktop/Models/UserPresenter.cs @@ -11,5 +11,6 @@ namespace Presence.Desktop.Models public int Id{ get; set; } public string Name { get; set; } public GroupPresenter Group { get; set; } + public PresencePresenter Presence { get; set; } } } \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index 07220ad..8efb2b4 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -11,11 +11,15 @@ using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows.Input; using Avalonia.Controls.Selection; +using presence.data.RemoteData.RemoteDataBase; +using presence.data.Repository; +using presence.domain.UseCase; namespace Presence.Desktop.ViewModels { public class GroupViewModel : ViewModelBase, IRoutableViewModel { + private readonly RemoteDataBaseContext _remoteDatabaseContext; public ICommand OpenFileDialog { get; } public Interaction SelectFileInteraction => _SelectFileInteraction; public readonly Interaction _SelectFileInteraction; @@ -48,10 +52,12 @@ namespace Presence.Desktop.ViewModels public ICommand RemoveUserCommand { get; } public ICommand EditUserCommand { get; } public ICommand RemoveAllSelectedCommand { get; } + public ICommand NavigateToPresenceCommand { get; } - public GroupViewModel(IGroupUseCase groupUseCase) + public GroupViewModel(IGroupUseCase groupUseCase, RemoteDataBaseContext remoteDataBaseContext) { _groupUseCase = groupUseCase; + _remoteDatabaseContext = remoteDataBaseContext; _SelectFileInteraction = new Interaction(); OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile); @@ -73,6 +79,7 @@ namespace Presence.Desktop.ViewModels RemoveUserCommand = ReactiveCommand.Create(RemoveUser); EditUserCommand = ReactiveCommand.Create(EditUser); RemoveAllSelectedCommand = ReactiveCommand.Create(RemoveAllSelected); + NavigateToPresenceCommand = ReactiveCommand.Create(NavigateToPresence); } private void SetUsers() @@ -154,5 +161,13 @@ namespace Presence.Desktop.ViewModels RefreshGroups(); SetUsers(); } + + private void NavigateToPresence() + { + var groupRepository = new SQLGroupRepositoryImpl(_remoteDatabaseContext); + var groupUseCase = new GroupUseCase(groupRepository); + + HostScreen.Router.Navigate.Execute(new PresenceViewModel(groupUseCase)); + } } } \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/PresenceViewModel.cs b/Presence.Desktop/ViewModels/PresenceViewModel.cs index e7f6127..6a2c64a 100644 --- a/Presence.Desktop/ViewModels/PresenceViewModel.cs +++ b/Presence.Desktop/ViewModels/PresenceViewModel.cs @@ -1,13 +1,106 @@ - using ReactiveUI; +using Avalonia.Data.Converters; +using presence.data.RemoteData.RemoteDataBase.DAO; +using presence.domain.Models; +using presence.domain.UseCase; +using Presence.Desktop.Models; +using Presence.Desktop.ViewModels; +using ReactiveUI; +using System; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Reactive; -namespace Presence.Desktop.ViewModels; - -public class PresenceViewModel: ViewModelBase, IRoutableViewModel +namespace Presence.Desktop.ViewModels { - public string? UrlPathSegment { get; } - public IScreen HostScreen { get; } + public class PresenceViewModel : ViewModelBase, IRoutableViewModel + { + public string? UrlPathSegment { get; } = "Presence"; + public IScreen HostScreen { get; } - -} + private readonly GroupUseCase _groupUseCase; + private readonly PresenceUseCase _presenceUseCase; - \ No newline at end of file + public ObservableCollection AttendanceRecords { get; set; } = new(); + public ObservableCollection Groups { get; set; } = new(); + + private GroupPresenter? _selectedGroup; + public GroupPresenter? SelectedGroup + { + get => _selectedGroup; + set + { + this.RaiseAndSetIfChanged(ref _selectedGroup, value); + FilterAttendanceRecords(); + } + } + + private DateOnly? _selectedDate; + public DateOnly? SelectedDate + { + get => _selectedDate; + set + { + this.RaiseAndSetIfChanged(ref _selectedDate, value); + FilterAttendanceRecords(); + } + } + + public ReactiveCommand NavigateBackCommand { get; } + + public PresenceViewModel(GroupUseCase groupUseCase) + { + _groupUseCase = groupUseCase; + + + NavigateBackCommand = ReactiveCommand.Create(() => { }); + + LoadGroups(); + } + + private void LoadGroups() + { + Groups.Clear(); + var groups = _groupUseCase.GetAllGroups(); + + foreach (var group in groups) + { + Groups.Add(new GroupPresenter + { + Id = group.Id, + Name = group.Name + }); + } + } + + private void FilterAttendanceRecords() + { + if (SelectedGroup == null || SelectedDate == null) + { + AttendanceRecords.Clear(); + return; + } + + var records = _presenceUseCase.GetPresenceByGroupAndDate( + SelectedGroup.Id, + SelectedDate.Value); + + AttendanceRecords.Clear(); + foreach (var record in records) + { + AttendanceRecords.Add(new PresencePresenter + { + Date = record.Date, + ClassNumber = record.ClassNumber, + IsAttendence = record.IsAttendence, + User = new UserPresenter + { + Id = record.User.Id, + Name= record.User.FIO + } + }); + } + } + + + } +} \ No newline at end of file diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index 4d6b5a5..d5f81dd 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -18,6 +18,11 @@ Margin="10,10,0,0" Foreground="Black" IsVisible="{Binding SelectedGroupItem, Converter={x:Static ObjectConverters.IsNotNull}}"/> +