set refresh changes

This commit is contained in:
KP9lKk 2024-12-05 11:35:52 +03:00
parent e1053ae6d7
commit e8e6221200
3 changed files with 41 additions and 25 deletions

View File

@ -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);
}
}
}

View File

@ -25,12 +25,38 @@ namespace Presence.Desktop.ViewModels
private GroupPresenter? _selectedGroupItem;
private IGroupUseCase _groupUseCase;
public ObservableCollection<UserPresenter> Users { get => _users;}
public ObservableCollection<UserPresenter> _users;
public GroupViewModel(IGroupUseCase groupUseCase)
{
foreach (var item in groupUseCase.GetGroupsWithStudents())
_groupUseCase = groupUseCase;
_users = new ObservableCollection<UserPresenter>();
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
{
@ -47,25 +73,7 @@ namespace Presence.Desktop.ViewModels
_groupPresentersDataSource.Add(groupPresenter);
}
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
_users = new ObservableCollection<UserPresenter>();
this.WhenAnyValue(vm => vm.SelectedGroupItem)
.Subscribe(_ => SetUsers());
}
private void SetUsers()
{
if(SelectedGroupItem == null) return;
if (SelectedGroupItem.users == null) return;
Users.Clear();
foreach (var item in SelectedGroupItem.users)
{
Users.Add(item);
}
}
public string? UrlPathSegment { get; }
public IScreen HostScreen { get; }
}

View File

@ -1,4 +1,4 @@
<Window xmlns="https://github.com/avaloniaui"
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:app="clr-namespace:Presence.Desktop"