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}}"/> +