diff --git a/Presence.Desktop/App.axaml b/Presence.Desktop/App.axaml index d3f2dbe..fb6e015 100644 --- a/Presence.Desktop/App.axaml +++ b/Presence.Desktop/App.axaml @@ -5,6 +5,7 @@ - - + + + \ No newline at end of file diff --git a/Presence.Desktop/Presence.Desktop.csproj b/Presence.Desktop/Presence.Desktop.csproj index ccd94d0..8e94e3c 100644 --- a/Presence.Desktop/Presence.Desktop.csproj +++ b/Presence.Desktop/Presence.Desktop.csproj @@ -15,6 +15,7 @@ + diff --git a/Presence.Desktop/ViewModels/PresenceViewModel.cs b/Presence.Desktop/ViewModels/PresenceViewModel.cs index c4a8bf8..ce76ecf 100644 --- a/Presence.Desktop/ViewModels/PresenceViewModel.cs +++ b/Presence.Desktop/ViewModels/PresenceViewModel.cs @@ -8,6 +8,7 @@ using ReactiveUI; using System; using System.Collections.ObjectModel; using System.Globalization; +using System.Linq; using System.Reactive; namespace Presence.Desktop.ViewModels @@ -22,6 +23,12 @@ namespace Presence.Desktop.ViewModels public ObservableCollection AttendanceRecords { get; set; } = new(); public ObservableCollection Groups { get; set; } = new(); + private ObservableCollection _selectedItems = new(); + public ObservableCollection SelectedItems + { + get => _selectedItems; + set => this.RaiseAndSetIfChanged(ref _selectedItems, value); + } private GroupPresenter? _selectedGroup; public GroupPresenter? SelectedGroup @@ -46,6 +53,7 @@ namespace Presence.Desktop.ViewModels } public ReactiveCommand NavigateBackCommand { get; } + public ReactiveCommand DeleteSelectedPresenceCommand { get; } public PresenceViewModel(GroupUseCase groupUseCase, PresenceUseCase presenceUseCase) { @@ -55,12 +63,9 @@ namespace Presence.Desktop.ViewModels NavigateBackCommand = ReactiveCommand.Create(() => { }); + DeleteSelectedPresenceCommand = ReactiveCommand.Create(DeleteSelectedItems); - this.WhenAnyValue(vm => vm.SelectedGroup) - .Subscribe(_ => - { - LoadGroups(); - }); + LoadGroups(); } private void LoadGroups() @@ -80,7 +85,7 @@ namespace Presence.Desktop.ViewModels private void FilterAttendanceRecords() { - if (SelectedGroup == null) + if (SelectedGroup == null || SelectedDate == null) { AttendanceRecords.Clear(); return; @@ -106,6 +111,21 @@ namespace Presence.Desktop.ViewModels } }); } + + // Логирование для отладки + Console.WriteLine($"Загружено записей посещаемости: {AttendanceRecords.Count}"); + } + + private void DeleteSelectedItems() + { + if (SelectedItems.Any()) + { + foreach (var item in SelectedItems.ToList()) + { + _presenceUseCase.DeletePresenceByClassNumberAndDateAndUserId(item.ClassNumber, item.Date, item.User.Id); // Удаляем из базы данных + AttendanceRecords.Remove(item); // Удаляем из коллекции + } + } } diff --git a/Presence.Desktop/Views/PresenceView.axaml b/Presence.Desktop/Views/PresenceView.axaml index 7c47916..5da2718 100644 --- a/Presence.Desktop/Views/PresenceView.axaml +++ b/Presence.Desktop/Views/PresenceView.axaml @@ -7,8 +7,8 @@ x:Class="Presence.Desktop.Views.PresenceView" x:DataType="vm:PresenceViewModel"> - - + + @@ -22,17 +22,18 @@ + - + - + - - - - +