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 domain.UseCase;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Presence.Api.Response; using Presence.Api.Response;
@ -33,5 +34,12 @@ namespace Presence.Api.Controllers
return Ok(result); return Ok(result);
} }
[HttpPost("/admin/{groupId}/students")]
public void AddGroup(int groupId, [FromBody] AddGroupRequest addGroupRequest)
{
Console.WriteLine(groupId);
_groupService.AddGroup(addGroupRequest);
}
} }
} }

View File

@ -25,47 +25,55 @@ namespace Presence.Desktop.ViewModels
private GroupPresenter? _selectedGroupItem; private GroupPresenter? _selectedGroupItem;
private IGroupUseCase _groupUseCase;
public ObservableCollection<UserPresenter> Users { get => _users;} public ObservableCollection<UserPresenter> Users { get => _users;}
public ObservableCollection<UserPresenter> _users; public ObservableCollection<UserPresenter> _users;
public GroupViewModel(IGroupUseCase groupUseCase) public GroupViewModel(IGroupUseCase groupUseCase)
{ {
foreach (var item in groupUseCase.GetGroupsWithStudents()) _groupUseCase = groupUseCase;
{
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<GroupPresenter>(_groupPresentersDataSource);
_users = new ObservableCollection<UserPresenter>(); _users = new ObservableCollection<UserPresenter>();
RefreshGroups();
this.WhenAnyValue(vm => vm.SelectedGroupItem) this.WhenAnyValue(vm => vm.SelectedGroupItem)
.Subscribe(_ => SetUsers()); .Subscribe(_ =>
{ RefreshGroups();
SetUsers();
});
} }
private void SetUsers() private void SetUsers()
{ {
if(SelectedGroupItem == null) return; if(SelectedGroupItem == null) return;
if (SelectedGroupItem.users == null) return;
Users.Clear(); 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); 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<GroupPresenter>(_groupPresentersDataSource);
}
public string? UrlPathSegment { get; } public string? UrlPathSegment { get; }
public IScreen HostScreen { 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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:app="clr-namespace:Presence.Desktop" xmlns:app="clr-namespace:Presence.Desktop"