diff --git a/Presence.Api/Controllers/GroupController.cs b/Presence.Api/Controllers/GroupController.cs index b748f37..b2c51f8 100644 --- a/Presence.Api/Controllers/GroupController.cs +++ b/Presence.Api/Controllers/GroupController.cs @@ -1,4 +1,5 @@ -using domain.Service; +using domain.Request; +using domain.Service; using domain.UseCase; using Microsoft.AspNetCore.Mvc; using Presence.Api.Response; @@ -33,5 +34,12 @@ namespace Presence.Api.Controllers return Ok(result); } + + [HttpPost("/admin/{groupId}/students")] + public void AddGroup(int groupId, [FromBody] AddGroupRequest addGroupRequest) + { + Console.WriteLine(groupId); + _groupService.AddGroup(addGroupRequest); + } } } diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index 99131e5..5a49629 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -25,47 +25,55 @@ namespace Presence.Desktop.ViewModels private GroupPresenter? _selectedGroupItem; - + private IGroupUseCase _groupUseCase; public ObservableCollection Users { get => _users;} public ObservableCollection _users; public GroupViewModel(IGroupUseCase groupUseCase) { - foreach (var item in groupUseCase.GetGroupsWithStudents()) - { - GroupPresenter groupPresenter = new GroupPresenter - { - Id = item.Id, - Name = item.Name, - users = item.Users?.Select(user => new UserPresenter - { - Name = user.Name, - Guid = user.Guid, - Group = new GroupPresenter { Id = item.Id, Name = item.Name } - } - ).ToList() - }; - _groupPresentersDataSource.Add(groupPresenter); - } - _groups = new ObservableCollection(_groupPresentersDataSource); - + _groupUseCase = groupUseCase; _users = new ObservableCollection(); - + RefreshGroups(); this.WhenAnyValue(vm => vm.SelectedGroupItem) - .Subscribe(_ => SetUsers()); + .Subscribe(_ => + { RefreshGroups(); + SetUsers(); + }); } private void SetUsers() { if(SelectedGroupItem == null) return; - if (SelectedGroupItem.users == null) return; Users.Clear(); - foreach (var item in SelectedGroupItem.users) + var group = _groups.First(it => it.Id == SelectedGroupItem.Id); + if(group.users == null) return; + foreach (var item in group.users) { Users.Add(item); } } + private void RefreshGroups() + { + _groupPresentersDataSource.Clear(); + foreach (var item in _groupUseCase.GetGroupsWithStudents()) + { + GroupPresenter groupPresenter = new GroupPresenter + { + Id = item.Id, + Name = item.Name, + users = item.Users?.Select(user => new UserPresenter + { + Name = user.Name, + 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; } } diff --git a/Presence.Desktop/Views/MainWindow.axaml b/Presence.Desktop/Views/MainWindow.axaml index 25f9e3a..58f7aa1 100644 --- a/Presence.Desktop/Views/MainWindow.axaml +++ b/Presence.Desktop/Views/MainWindow.axaml @@ -1,4 +1,4 @@ -