set refresh changes
This commit is contained in:
parent
e1053ae6d7
commit
e8e6221200
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,47 +25,55 @@ 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())
|
||||
{
|
||||
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);
|
||||
|
||||
_groupUseCase = groupUseCase;
|
||||
_users = new ObservableCollection<UserPresenter>();
|
||||
|
||||
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<GroupPresenter>(_groupPresentersDataSource);
|
||||
}
|
||||
public string? UrlPathSegment { get; }
|
||||
public IScreen HostScreen { get; }
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user