diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index f5dbf04..9c36b07 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -19,6 +19,13 @@ namespace Presence.Desktop.ViewModels private ObservableCollection _groups; public ObservableCollection Groups => _groups; private GroupPresenter? _selectedGroupItem; + public ObservableCollection Users { get => _users;} + public ObservableCollection _users; + + + private ObservableCollection _secondComboBoxItems = new ObservableCollection { "no sort", "name sort", "name sort rev" }; + public ObservableCollection SecondComboBoxItems => _secondComboBoxItems; + private string? _selectedSecondItem; public ReactiveCommand ButtonRemoveUsersByGroup {get; } // public ReactiveCommand ButtonAddUser { get; } @@ -30,8 +37,11 @@ namespace Presence.Desktop.ViewModels } - public ObservableCollection Users { get => _users;} - public ObservableCollection _users; + public string? SelectedSecondItem + { + get => _selectedSecondItem; + set => this.RaiseAndSetIfChanged(ref _selectedSecondItem, value); + } public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase) { foreach (var item in groupUseCase.GetAllGroupsWithUsers()) @@ -57,6 +67,11 @@ namespace Presence.Desktop.ViewModels this.WhenAnyValue(vm => vm.SelectedGroupItem) .Subscribe(_ => SetUsers()); + + this.WhenAnyValue(vm => vm.SelectedSecondItem) + .Subscribe(_ => SetUsers()); + + SelectedSecondItem = _secondComboBoxItems.First(); ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup(groupUseCase)); } @@ -65,8 +80,15 @@ namespace Presence.Desktop.ViewModels { if(SelectedGroupItem == null) return; if (SelectedGroupItem.users == null) return; + var sortedUsers = SelectedSecondItem switch + { + "name sort" => SelectedGroupItem.users.OrderBy(user => user.Name), + "name sort rev" => SelectedGroupItem.users.OrderByDescending(user => user.Name), + _ => SelectedGroupItem.users + }; + Users.Clear(); - foreach (var item in SelectedGroupItem.users) + foreach (var item in sortedUsers) { Users.Add(item); } diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index 44c2d7d..0bb45cb 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -12,14 +12,11 @@ - -