From 57da9f595adc9e04fc02459f82d5ab33106f3cc1 Mon Sep 17 00:00:00 2001 From: Class_Student Date: Wed, 18 Dec 2024 10:19:58 +0300 Subject: [PATCH] init commit --- Presence.Desktop/App.axaml | 4 - Presence.Desktop/App.axaml.cs | 10 +- .../DI/ServiceCollectionExtensions.cs | 2 +- Presence.Desktop/Presence.Desktop.csproj | 6 + Presence.Desktop/ViewLocator.cs | 29 +-- Presence.Desktop/ViewModels/GroupViewModel.cs | 239 ++++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 239 +----------------- .../ViewModels/PresenceViewModel.cs | 9 + Presence.Desktop/Views/GroupView.axaml | 145 +++++++++++ Presence.Desktop/Views/GroupView.axaml.cs | 30 +++ Presence.Desktop/Views/MainWindow.axaml | 128 +--------- Presence.Desktop/Views/MainWindow.axaml.cs | 30 +-- Presence.Desktop/Views/PresenceView.axaml | 10 + Presence.Desktop/Views/PresenceView.axaml.cs | 17 ++ .../bin/Debug/net8.0/Presence.Desktop.dll | Bin 224768 -> 224768 bytes .../bin/Debug/net8.0/Presence.Desktop.exe | Bin 143360 -> 143360 bytes .../bin/Debug/net8.0/Presence.Desktop.pdb | Bin 21456 -> 21456 bytes Presence.Desktop/bin/Debug/net8.0/data.dll | Bin 34304 -> 34304 bytes Presence.Desktop/bin/Debug/net8.0/data.pdb | Bin 19900 -> 19900 bytes Presence.Desktop/bin/Debug/net8.0/domain.dll | Bin 22016 -> 22016 bytes Presence.Desktop/bin/Debug/net8.0/domain.pdb | Bin 18340 -> 18340 bytes .../net8.0/Avalonia/Presence.Desktop.dll | Bin 224768 -> 224768 bytes .../net8.0/Avalonia/Presence.Desktop.pdb | Bin 21456 -> 21456 bytes .../net8.0/Avalonia/Resources.Inputs.cache | 2 +- .../obj/Debug/net8.0/Avalonia/references | 4 +- .../obj/Debug/net8.0/Avalonia/resources | Bin 182741 -> 183571 bytes .../net8.0/Presence.Desktop.AssemblyInfo.cs | 2 +- .../Presence.Desktop.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 14 +- .../net8.0/Presence.Desktop.assets.cache | Bin 39158 -> 39158 bytes ...nce.Desktop.csproj.AssemblyReference.cache | Bin 33426 -> 33426 bytes ...nce.Desktop.csproj.CoreCompileInputs.cache | 2 +- ...esence.Desktop.csproj.FileListAbsolute.txt | 3 + .../obj/Debug/net8.0/Presence.Desktop.dll | Bin 206336 -> 206336 bytes .../Presence.Desktop.genruntimeconfig.cache | 2 +- .../obj/Debug/net8.0/Presence.Desktop.pdb | Bin 20124 -> 20124 bytes Presence.Desktop/obj/Debug/net8.0/apphost.exe | Bin 143360 -> 143360 bytes .../obj/Debug/net8.0/ref/Presence.Desktop.dll | Bin 10752 -> 10752 bytes .../refint/Avalonia/Presence.Desktop.dll | Bin 10752 -> 10752 bytes .../Debug/net8.0/refint/Presence.Desktop.dll | Bin 11264 -> 11264 bytes .../Presence.Desktop.csproj.nuget.dgspec.json | 38 +-- Presence.Desktop/obj/project.assets.json | 14 +- Presence.Desktop/obj/project.nuget.cache | 4 +- .../Debug/net8.0/console_ui.AssemblyInfo.cs | 2 +- .../console_ui.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 2 +- .../obj/Debug/net8.0/console_ui.assets.cache | Bin 15046 -> 15046 bytes .../console_ui.csproj.AssemblyReference.cache | Bin 14468 -> 14468 bytes .../obj/console_ui.csproj.nuget.dgspec.json | 54 ++-- console_ui/obj/project.assets.json | 18 +- console_ui/obj/project.nuget.cache | 4 +- data/bin/Debug/net8.0/data.dll | Bin 34304 -> 34304 bytes data/bin/Debug/net8.0/data.pdb | Bin 19900 -> 19900 bytes data/obj/Debug/net8.0/data.AssemblyInfo.cs | 2 +- .../net8.0/data.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 2 +- data/obj/Debug/net8.0/data.assets.cache | Bin 37208 -> 37208 bytes data/obj/Debug/net8.0/data.dll | Bin 34304 -> 34304 bytes .../Debug/net8.0/data.genruntimeconfig.cache | 2 +- data/obj/Debug/net8.0/data.pdb | Bin 19900 -> 19900 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 data/obj/data.csproj.nuget.dgspec.json | 10 +- data/obj/project.nuget.cache | 4 +- domain/bin/Debug/net8.0/data.dll | Bin 34304 -> 34304 bytes domain/bin/Debug/net8.0/data.pdb | Bin 19900 -> 19900 bytes domain/bin/Debug/net8.0/domain.dll | Bin 22016 -> 22016 bytes domain/bin/Debug/net8.0/domain.pdb | Bin 18340 -> 18340 bytes .../obj/Debug/net8.0/domain.AssemblyInfo.cs | 2 +- .../net8.0/domain.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 2 +- domain/obj/Debug/net8.0/domain.assets.cache | Bin 14690 -> 14690 bytes .../domain.csproj.AssemblyReference.cache | Bin 14589 -> 14589 bytes domain/obj/Debug/net8.0/domain.dll | Bin 22016 -> 22016 bytes domain/obj/Debug/net8.0/domain.pdb | Bin 18340 -> 18340 bytes domain/obj/Debug/net8.0/ref/domain.dll | Bin 10240 -> 10240 bytes domain/obj/Debug/net8.0/refint/domain.dll | Bin 10240 -> 10240 bytes domain/obj/domain.csproj.nuget.dgspec.json | 22 +- domain/obj/project.assets.json | 10 +- domain/obj/project.nuget.cache | 4 +- .../Debug/net8.0/presence_api.AssemblyInfo.cs | 2 +- .../presence_api.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 4 +- .../Debug/net8.0/presence_api.assets.cache | Bin 18611 -> 18611 bytes ...resence_api.csproj.AssemblyReference.cache | Bin 14600 -> 15825 bytes .../obj/presence_api.csproj.nuget.dgspec.json | 34 +-- presence_api/obj/project.assets.json | 10 +- presence_api/obj/project.nuget.cache | 4 +- ui/obj/Debug/net8.0/ui.AssemblyInfo.cs | 2 +- .../Debug/net8.0/ui.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 2 +- ui/obj/Debug/net8.0/ui.assets.cache | Bin 14558 -> 14558 bytes .../net8.0/ui.csproj.AssemblyReference.cache | Bin 14173 -> 14173 bytes ui/obj/project.assets.json | 10 +- ui/obj/project.nuget.cache | 4 +- ui/obj/ui.csproj.nuget.dgspec.json | 34 +-- 96 files changed, 678 insertions(+), 563 deletions(-) create mode 100644 Presence.Desktop/ViewModels/GroupViewModel.cs create mode 100644 Presence.Desktop/ViewModels/PresenceViewModel.cs create mode 100644 Presence.Desktop/Views/GroupView.axaml create mode 100644 Presence.Desktop/Views/GroupView.axaml.cs create mode 100644 Presence.Desktop/Views/PresenceView.axaml create mode 100644 Presence.Desktop/Views/PresenceView.axaml.cs diff --git a/Presence.Desktop/App.axaml b/Presence.Desktop/App.axaml index 6e40e93..e74235a 100644 --- a/Presence.Desktop/App.axaml +++ b/Presence.Desktop/App.axaml @@ -1,13 +1,9 @@ - - - diff --git a/Presence.Desktop/App.axaml.cs b/Presence.Desktop/App.axaml.cs index dcc513c..20da721 100644 --- a/Presence.Desktop/App.axaml.cs +++ b/Presence.Desktop/App.axaml.cs @@ -26,18 +26,18 @@ namespace Presence.Desktop var services = serviceCollection.BuildServiceProvider(); - var mainViewModel = services.GetRequiredService(); + var mainViewModel = services.GetRequiredService(); + - var groupUseCase = services.GetRequiredService(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - - desktop.MainWindow = new MainWindow(groupUseCase) + + desktop.MainWindow = new MainWindow() { - DataContext = mainViewModel, + DataContext = new MainWindowViewModel(services), }; } diff --git a/Presence.Desktop/DI/ServiceCollectionExtensions.cs b/Presence.Desktop/DI/ServiceCollectionExtensions.cs index de132d4..12a21ac 100644 --- a/Presence.Desktop/DI/ServiceCollectionExtensions.cs +++ b/Presence.Desktop/DI/ServiceCollectionExtensions.cs @@ -18,7 +18,7 @@ namespace Presence.Desktop.DI .AddSingleton() .AddSingleton() .AddTransient() - .AddTransient(); + .AddTransient(); } } } \ No newline at end of file diff --git a/Presence.Desktop/Presence.Desktop.csproj b/Presence.Desktop/Presence.Desktop.csproj index 92a908c..337988a 100644 --- a/Presence.Desktop/Presence.Desktop.csproj +++ b/Presence.Desktop/Presence.Desktop.csproj @@ -31,4 +31,10 @@ + + + + GroupView.axaml + + diff --git a/Presence.Desktop/ViewLocator.cs b/Presence.Desktop/ViewLocator.cs index 74b8a57..2da0eb6 100644 --- a/Presence.Desktop/ViewLocator.cs +++ b/Presence.Desktop/ViewLocator.cs @@ -2,31 +2,18 @@ using Avalonia.Controls; using Avalonia.Controls.Templates; using Presence.Desktop.ViewModels; using System; +using Presence.Desktop.Views; +using ReactiveUI; namespace Presence.Desktop { - public class ViewLocator : IDataTemplate + public class ViewLocator : IViewLocator { - - public Control? Build(object? param) + public IViewFor? ResolveView(T? viewModel, string? contract = null) => viewModel switch { - if (param is null) - return null; - - var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); - var type = Type.GetType(name); - - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } - - return new TextBlock { Text = "Not Found: " + name }; - } - - public bool Match(object? data) - { - return data is ViewModelBase; - } + GroupViewModel groupViewModel => new GroupView { DataContext = groupViewModel }, + PresenceViewModel presenceViewModel => new PresenceView { DataContext = presenceViewModel }, + _ => throw new ArgumentOutOfRangeException(nameof(viewModel)) + }; } } diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs new file mode 100644 index 0000000..e7c746d --- /dev/null +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -0,0 +1,239 @@ +using Avalonia.Controls.ApplicationLifetimes; +using domain.Models; +using domain.UseCase; +using Presence.Desktop.Views; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive; +using System.Reactive.Linq; +using System.Windows.Input; +using Avalonia; + +namespace Presence.Desktop.ViewModels +{ + public class GroupViewModel : ViewModelBase, IRoutableViewModel + { + private readonly GroupUseCase _groupUseCase; + private List groupPresentersDataSource = new List(); + private ObservableCollection _groups; + public ObservableCollection Groups => _groups; + + private GroupPresenter? _selectedGroupItem; + public GroupPresenter? SelectedGroupItem + { + get => _selectedGroupItem; + set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); + } + + public ObservableCollection Users { get => _users; } + private ObservableCollection _users; + + // Список опций сортировки + public List SortOptions { get; } = new List { "По фамилии", "По убыванию" }; + + private string _selectedSortOption; + public string SelectedSortOption + { + get => _selectedSortOption; + set => this.RaiseAndSetIfChanged(ref _selectedSortOption, value); + } + + public bool CanDelete => SelectedUsers?.Count > 0; + public bool CanEdit => SelectedUsers?.Count == 1; + + public ObservableCollection SelectedUsers { get; set; } = new ObservableCollection(); + + public ReactiveCommand OnDeleteUserClicks { get; } + public ReactiveCommand EditUserCommand { get; } + public ICommand RemoveAllStudentsCommand { get; } + public ICommand AddStudentCommand { get; } + + public GroupViewModel(GroupUseCase groupUseCase) + { + _groupUseCase = groupUseCase; + + OnDeleteUserClicks = ReactiveCommand.Create(OnDeleteUserClick, this.WhenAnyValue(vm => vm.CanDelete)); + EditUserCommand = ReactiveCommand.Create(OnEditUserClick, this.WhenAnyValue(vm => vm.CanEdit)); + + RefreshGroups(); + + _groups = new ObservableCollection(groupPresentersDataSource); + _users = new ObservableCollection(); + + this.WhenAnyValue(vm => vm.SelectedGroupItem) + .Subscribe(vm => SetUsers()); + + this.WhenAnyValue(vm => vm.SelectedSortOption) + .Subscribe(_ => SortUsers()); + + RemoveAllStudentsCommand = ReactiveCommand.Create(RemoveAllStudents); + AddStudentCommand = ReactiveCommand.Create(AddStudent); + + SelectedUsers.CollectionChanged += (s, e) => + { + this.RaisePropertyChanged(nameof(CanDelete)); + this.RaisePropertyChanged(nameof(CanEdit)); + }; + } + + private void SetUsers() + { + if (SelectedGroupItem?.users == null) return; + + Users.Clear(); + foreach (var item in SelectedGroupItem.users) + { + Users.Add(item); + } + + SortUsers(); + } + + private void SortUsers() + { + if (SelectedGroupItem?.users == null) return; + + var sortedUsers = SelectedGroupItem.users.ToList(); + + switch (SelectedSortOption) + { + case "По фамилии": + sortedUsers = sortedUsers.OrderBy(u => u.Name).ToList(); + break; + case "По убыванию": + sortedUsers = sortedUsers.OrderByDescending(u => u.Name).ToList(); + break; + } + + Users.Clear(); + foreach (var item in sortedUsers) + { + Users.Add(item); + } + } + + private void RemoveAllStudents() + { + if (SelectedGroupItem == null) return; + + _groupUseCase.RemoveAllStudentsFromGroup(SelectedGroupItem.Id); + SelectedGroupItem.users = new List(); + SetUsers(); + } + + private void AddStudent() + { + if (SelectedGroupItem == null) return; + + var newStudent = new UserPresenter + { + Name = "Новый студент", + Guid = Guid.NewGuid(), + Group = SelectedGroupItem + }; + + _groupUseCase.AddStudentToGroup(SelectedGroupItem.Id, new User + { + Guid = newStudent.Guid, + FIO = newStudent.Name + }); + + var updatedUsers = SelectedGroupItem.users?.ToList() ?? new List(); + updatedUsers.Add(newStudent); + SelectedGroupItem.users = updatedUsers; + SetUsers(); + } + + public void OnDeleteUserClick() + { + if (SelectedUsers.Count == 0 || SelectedGroupItem?.users == null) + return; + + foreach (var user in SelectedUsers.ToList()) + { + _groupUseCase.RemoveUserByGuid(user.Guid); + + var updatedUsers = SelectedGroupItem.users.Where(u => u.Guid != user.Guid).ToList(); + SelectedGroupItem.users = new List(updatedUsers); + } + + SetUsers(); + SelectedUsers.Clear(); + this.RaisePropertyChanged(nameof(CanDelete)); + this.RaisePropertyChanged(nameof(CanEdit)); + } + + public async void OnEditUserClick() + { + var user = SelectedUsers.FirstOrDefault(); + if (user == null) return; + + var groups = _groupUseCase.GetAllGroups(); + + // Преобразуем группы из domain.Models.Group в GroupPresenter + var groupPresenters = groups.Select(g => new GroupPresenter + { + Id = g.Id, + Name = g.Name, + users = g.Users?.Select(u => new UserPresenter + { + Name = u.FIO, + Guid = u.Guid, + Group = new GroupPresenter { Id = g.Id, Name = g.Name } + }).ToList() + }).ToList(); + + var editDialog = new EditUserDialog(user.Guid, user.Name, user.Group.Id, groupPresenters); + + var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow; + if (mainWindow == null) return; + + var result = await editDialog.ShowDialog(mainWindow); + + if (result != (null, null)) + { + var newName = result.Item1; + var newGroup = result.Item2; + + user.Name = newName; + user.Group = newGroup; + + _groupUseCase.UpdateUser(user.Guid, user.Name, user.Group.Id); + + SetUsers(); + SelectedUsers.Clear(); + this.RaisePropertyChanged(nameof(CanEdit)); + this.RaisePropertyChanged(nameof(CanDelete)); + } + RefreshGroups(); + } + + private void RefreshGroups() + { + groupPresentersDataSource.Clear(); + foreach (var item in _groupUseCase.GetAllGroups()) + { + GroupPresenter groupPresenter = new GroupPresenter + { + Id = item.Id, + Name = item.Name, + users = item.Users?.Select(user => new UserPresenter + { + Name = user.FIO, + Guid = user.Guid, + Group = new GroupPresenter { Id = item.Id, Name = item.Name } + }).ToList() + }; + groupPresentersDataSource.Add(groupPresenter); + } + _groups = new ObservableCollection(groupPresentersDataSource); + } + public string? UrlPathSegment { get; } + public IScreen HostScreen { get; } + + + } +} \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/MainWindowViewModel.cs b/Presence.Desktop/ViewModels/MainWindowViewModel.cs index 79ca60c..8449f0d 100644 --- a/Presence.Desktop/ViewModels/MainWindowViewModel.cs +++ b/Presence.Desktop/ViewModels/MainWindowViewModel.cs @@ -1,235 +1,16 @@ -using Avalonia.Controls.ApplicationLifetimes; -using domain.Models; -using domain.UseCase; -using Presence.Desktop.Views; +using System; +using Microsoft.Extensions.DependencyInjection; using ReactiveUI; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reactive; -using System.Reactive.Linq; -using System.Windows.Input; -using Avalonia; -namespace Presence.Desktop.ViewModels +namespace Presence.Desktop.ViewModels; + +public class MainWindowViewModel : ViewModelBase, IScreen { - public class MainWindowViewModel : ViewModelBase + public RoutingState Router { get; } = new RoutingState(); + + public MainWindowViewModel(IServiceProvider serviceProvider) { - private readonly GroupUseCase _groupUseCase; - private List groupPresentersDataSource = new List(); - private ObservableCollection _groups; - public ObservableCollection Groups => _groups; - - private GroupPresenter? _selectedGroupItem; - public GroupPresenter? SelectedGroupItem - { - get => _selectedGroupItem; - set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); - } - - public ObservableCollection Users { get => _users; } - private ObservableCollection _users; - - // Список опций сортировки - public List SortOptions { get; } = new List { "По фамилии", "По убыванию" }; - - private string _selectedSortOption; - public string SelectedSortOption - { - get => _selectedSortOption; - set => this.RaiseAndSetIfChanged(ref _selectedSortOption, value); - } - - public bool CanDelete => SelectedUsers?.Count > 0; - public bool CanEdit => SelectedUsers?.Count == 1; - - public ObservableCollection SelectedUsers { get; set; } = new ObservableCollection(); - - public ReactiveCommand OnDeleteUserClicks { get; } - public ReactiveCommand EditUserCommand { get; } - public ICommand RemoveAllStudentsCommand { get; } - public ICommand AddStudentCommand { get; } - - public MainWindowViewModel(GroupUseCase groupUseCase) - { - _groupUseCase = groupUseCase; - - OnDeleteUserClicks = ReactiveCommand.Create(OnDeleteUserClick, this.WhenAnyValue(vm => vm.CanDelete)); - EditUserCommand = ReactiveCommand.Create(OnEditUserClick, this.WhenAnyValue(vm => vm.CanEdit)); - - RefreshGroups(); - - _groups = new ObservableCollection(groupPresentersDataSource); - _users = new ObservableCollection(); - - this.WhenAnyValue(vm => vm.SelectedGroupItem) - .Subscribe(vm => SetUsers()); - - this.WhenAnyValue(vm => vm.SelectedSortOption) - .Subscribe(_ => SortUsers()); - - RemoveAllStudentsCommand = ReactiveCommand.Create(RemoveAllStudents); - AddStudentCommand = ReactiveCommand.Create(AddStudent); - - SelectedUsers.CollectionChanged += (s, e) => - { - this.RaisePropertyChanged(nameof(CanDelete)); - this.RaisePropertyChanged(nameof(CanEdit)); - }; - } - - private void SetUsers() - { - if (SelectedGroupItem?.users == null) return; - - Users.Clear(); - foreach (var item in SelectedGroupItem.users) - { - Users.Add(item); - } - - SortUsers(); - } - - private void SortUsers() - { - if (SelectedGroupItem?.users == null) return; - - var sortedUsers = SelectedGroupItem.users.ToList(); - - switch (SelectedSortOption) - { - case "По фамилии": - sortedUsers = sortedUsers.OrderBy(u => u.Name).ToList(); - break; - case "По убыванию": - sortedUsers = sortedUsers.OrderByDescending(u => u.Name).ToList(); - break; - } - - Users.Clear(); - foreach (var item in sortedUsers) - { - Users.Add(item); - } - } - - private void RemoveAllStudents() - { - if (SelectedGroupItem == null) return; - - _groupUseCase.RemoveAllStudentsFromGroup(SelectedGroupItem.Id); - SelectedGroupItem.users = new List(); - SetUsers(); - } - - private void AddStudent() - { - if (SelectedGroupItem == null) return; - - var newStudent = new UserPresenter - { - Name = "Новый студент", - Guid = Guid.NewGuid(), - Group = SelectedGroupItem - }; - - _groupUseCase.AddStudentToGroup(SelectedGroupItem.Id, new User - { - Guid = newStudent.Guid, - FIO = newStudent.Name - }); - - var updatedUsers = SelectedGroupItem.users?.ToList() ?? new List(); - updatedUsers.Add(newStudent); - SelectedGroupItem.users = updatedUsers; - SetUsers(); - } - - public void OnDeleteUserClick() - { - if (SelectedUsers.Count == 0 || SelectedGroupItem?.users == null) - return; - - foreach (var user in SelectedUsers.ToList()) - { - _groupUseCase.RemoveUserByGuid(user.Guid); - - var updatedUsers = SelectedGroupItem.users.Where(u => u.Guid != user.Guid).ToList(); - SelectedGroupItem.users = new List(updatedUsers); - } - - SetUsers(); - SelectedUsers.Clear(); - this.RaisePropertyChanged(nameof(CanDelete)); - this.RaisePropertyChanged(nameof(CanEdit)); - } - - public async void OnEditUserClick() - { - var user = SelectedUsers.FirstOrDefault(); - if (user == null) return; - - var groups = _groupUseCase.GetAllGroups(); - - // Преобразуем группы из domain.Models.Group в GroupPresenter - var groupPresenters = groups.Select(g => new GroupPresenter - { - Id = g.Id, - Name = g.Name, - users = g.Users?.Select(u => new UserPresenter - { - Name = u.FIO, - Guid = u.Guid, - Group = new GroupPresenter { Id = g.Id, Name = g.Name } - }).ToList() - }).ToList(); - - var editDialog = new EditUserDialog(user.Guid, user.Name, user.Group.Id, groupPresenters); - - var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow; - if (mainWindow == null) return; - - var result = await editDialog.ShowDialog(mainWindow); - - if (result != (null, null)) - { - var newName = result.Item1; - var newGroup = result.Item2; - - user.Name = newName; - user.Group = newGroup; - - _groupUseCase.UpdateUser(user.Guid, user.Name, user.Group.Id); - - SetUsers(); - SelectedUsers.Clear(); - this.RaisePropertyChanged(nameof(CanEdit)); - this.RaisePropertyChanged(nameof(CanDelete)); - } - RefreshGroups(); - } - - private void RefreshGroups() - { - groupPresentersDataSource.Clear(); - foreach (var item in _groupUseCase.GetAllGroups()) - { - GroupPresenter groupPresenter = new GroupPresenter - { - Id = item.Id, - Name = item.Name, - users = item.Users?.Select(user => new UserPresenter - { - Name = user.FIO, - Guid = user.Guid, - Group = new GroupPresenter { Id = item.Id, Name = item.Name } - }).ToList() - }; - groupPresentersDataSource.Add(groupPresenter); - } - _groups = new ObservableCollection(groupPresentersDataSource); - } + var groupViewModel = serviceProvider.GetRequiredService(); + Router.Navigate.Execute(groupViewModel); } } \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/PresenceViewModel.cs b/Presence.Desktop/ViewModels/PresenceViewModel.cs new file mode 100644 index 0000000..4c06266 --- /dev/null +++ b/Presence.Desktop/ViewModels/PresenceViewModel.cs @@ -0,0 +1,9 @@ +using ReactiveUI; + +namespace Presence.Desktop.ViewModels; + +public class PresenceViewModel : ViewModelBase, IRoutableViewModel +{ + public string? UrlPathSegment { get; } + public IScreen HostScreen { get; } +} diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml new file mode 100644 index 0000000..854428d --- /dev/null +++ b/Presence.Desktop/Views/GroupView.axaml @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +