diff --git a/Presence.Api/Controllers/GroupController.cs b/Presence.Api/Controllers/GroupController.cs index f692ba0..142f999 100644 --- a/Presence.Api/Controllers/GroupController.cs +++ b/Presence.Api/Controllers/GroupController.cs @@ -1,5 +1,7 @@ using domain.Service; using domain.UseCase; +using domain.Request; +using domain.Service; using Microsoft.AspNetCore.Mvc; using Presence.Api.Response; @@ -31,6 +33,13 @@ namespace Presence.Api.Controllers }).ToList(), }).ToList(); return Ok(new GroupResponse()); - } + } + + [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 6a27cc7..3522b81 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -1,6 +1,4 @@ using domain.UseCase; -using DynamicData; -using DynamicData.Binding; using Presence.Desktop.Models; using ReactiveUI; using System; @@ -8,12 +6,23 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Reactive.Linq; -using Tmds.DBus.Protocol; +using System.Threading.Tasks; +using System.Windows.Input; namespace Presence.Desktop.ViewModels { public class GroupViewModel : ViewModelBase, IRoutableViewModel { + public ICommand OpenFileDialog { get; } + public Interaction SelectFileInteraction => _SelectFileInteraction; + public readonly Interaction _SelectFileInteraction; + private string? _selectedFile; + public string? SelectedFile + { + get => _selectedFile; + set => this.RaiseAndSetIfChanged(ref _selectedFile, value); + } + private readonly List _groupPresentersDataSource = new List(); private ObservableCollection _groups; public ObservableCollection Groups => _groups; @@ -27,12 +36,40 @@ 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()) + _groupUseCase = groupUseCase; + _SelectFileInteraction = new Interaction(); + OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile); + _users = new ObservableCollection(); + RefreshGroups(); + this.WhenAnyValue(vm => vm.SelectedGroupItem) + .Subscribe(_ => + { + RefreshGroups(); + SetUsers(); + }); + } + + private void SetUsers() + { + if (SelectedGroupItem == null) return; + Users.Clear(); + 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 { @@ -49,26 +86,15 @@ namespace Presence.Desktop.ViewModels _groupPresentersDataSource.Add(groupPresenter); } _groups = new ObservableCollection(_groupPresentersDataSource); - - _users = new ObservableCollection(); - - this.WhenAnyValue(vm => vm.SelectedGroupItem) - .Subscribe(_ => SetUsers()); - } - private void SetUsers() + private async Task SelectFile() { - if (SelectedGroupItem == null) return; - if (SelectedGroupItem.users == null) return; - Users.Clear(); - foreach (var item in SelectedGroupItem.users) - { - Users.Add(item); - } + Console.WriteLine("clock"); + SelectedFile = await _SelectFileInteraction.Handle("Chose csv file"); } - public string? UrlPathSegment { get; } public IScreen HostScreen { get; } } } + diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index 6789a99..d1aed66 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -4,7 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:Presence.Desktop.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Presence.Desktop.GroupView" + x:Class="Presence.Desktop.Views.GroupView" x:DataType="vm:GroupViewModel"> @@ -27,7 +27,7 @@ - +