diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index b261240..87b31e3 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -1,177 +1,3 @@ -// using Demo.Domain.Models; -// using Demo.Domain.UseCase; -// using DynamicData; -// using DynamicData.Binding; -// using Presence.Desktop.Models; -// using ReactiveUI; -// using System; -// using System.Collections.Generic; -// using System.Collections.ObjectModel; -// using System.IO; -// using System.Linq; -// using System.Reactive; -// using System.Reactive.Linq; -// using Tmds.DBus.Protocol; -// using Avalonia.Controls; - -// namespace Presence.Desktop.ViewModels -// { -// public class GroupViewModel : ViewModelBase, IRoutableViewModel -// { -// private readonly List _groupPresentersDataSource = new List(); -// 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 ImportStudentsCommand { get; } - -// public GroupPresenter? SelectedGroupItem -// { -// get => _selectedGroupItem; -// set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); -// } - - -// public string? SelectedSecondItem -// { -// get => _selectedSecondItem; -// set => this.RaiseAndSetIfChanged(ref _selectedSecondItem, value); -// } -// public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase) -// { -// foreach (var item in groupUseCase.GetAllGroupsWithUsers()) -// { -// 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); - -// _users = new ObservableCollection(); - -// this.WhenAnyValue(vm => vm.SelectedGroupItem) -// .Subscribe(_ => SetUsers()); - -// this.WhenAnyValue(vm => vm.SelectedSecondItem) -// .Subscribe(_ => SetUsers()); - -// SelectedSecondItem = _secondComboBoxItems.First(); -// ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup(groupUseCase)); -// ImportStudentsCommand = ReactiveCommand.CreateFromTask(async () => -// { -// var openFileDialog = new OpenFileDialog -// { -// Filters = new List -// { -// new FileDialogFilter { Name = "CSV Files", Extensions = { "csv" } } -// }, -// AllowMultiple = false -// }; - -// var result = await openFileDialog.ShowAsync(new Window()); -// if (result?.Length > 0) { -// var filePath = result[0]; -// ImportStudents(filePath, userUseCase); -// } -// }); -// } - -// private void SetUsers() -// { -// 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 sortedUsers) -// { -// Users.Add(item); -// } -// } - -// private void RemoveUsersByGroup(IGroupUseCase groupUseCase) -// { -// if (_selectedGroupItem != null){ -// groupUseCase.RemoveUsersByGroup(_selectedGroupItem.Id); -// } - -// var usersToRemove = Users.Where(user => user.Group.Id == _selectedGroupItem.Id).ToList(); -// foreach (var user in usersToRemove) -// { -// Users.Remove(user); -// } -// } - -// private void ImportStudents(string filePath, IUserUseCase userUseCase) -// { -// if (SelectedGroupItem == null || SelectedGroupItem.Id == null) -// { -// return; -// } -// var lines = File.ReadAllLines(filePath); - -// foreach (var line in lines.Skip(1)) -// { -// var columns = line.Split(','); -// if (columns.Length < 1) continue; - -// var fio = columns[0]; - -// var newUser = new User -// { -// FIO = fio, -// Group = new Group -// { -// Name = SelectedGroupItem.Name, -// ID = SelectedGroupItem.Id -// } -// }; - -// var result = userUseCase.CreateUser(newUser); - -// if (result) -// { -// var userPresenter = new UserPresenter -// { -// Name = fio, -// Guid = Guid.NewGuid(), -// Group = SelectedGroupItem -// }; -// _users.Add(userPresenter); -// } -// } -// } - -// public string? UrlPathSegment { get; } -// public IScreen HostScreen { get; } -// } -// } - - using Demo.Domain.Models; using Demo.Domain.UseCase; using DynamicData;