2024-11-18 16:36:42 +00:00
|
|
|
|
using data.DAO;
|
|
|
|
|
using data.Repository;
|
2024-12-04 21:58:43 +00:00
|
|
|
|
using domain.Entity;
|
2024-11-16 21:45:57 +00:00
|
|
|
|
using domain.Request;
|
|
|
|
|
using domain.UseCase;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace domain.Service
|
|
|
|
|
{
|
|
|
|
|
public class GroupService : IGroupUseCase
|
|
|
|
|
{
|
|
|
|
|
private readonly IGroupRepository _groupRepository;
|
|
|
|
|
public GroupService(IGroupRepository groupRepository)
|
|
|
|
|
{
|
|
|
|
|
_groupRepository = groupRepository;
|
|
|
|
|
}
|
|
|
|
|
public void AddGroup(AddGroupRequest addGroupRequest)
|
|
|
|
|
{
|
|
|
|
|
_groupRepository.addGroup(new data.DAO.GroupDAO { Name = addGroupRequest.Name });
|
|
|
|
|
}
|
2024-11-18 16:36:42 +00:00
|
|
|
|
|
|
|
|
|
public void AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents)
|
|
|
|
|
{
|
|
|
|
|
GroupDAO groupDAO = new GroupDAO() { Name = addGroupWithStudents.addGroupRequest.Name };
|
|
|
|
|
List<UserDAO> users = addGroupWithStudents.addStudentRequests
|
|
|
|
|
.Select(it => new UserDAO { Name = it.StudentName })
|
|
|
|
|
.ToList();
|
|
|
|
|
_groupRepository.addGroupWithStudents(groupDAO, users);
|
|
|
|
|
}
|
2024-12-04 21:58:43 +00:00
|
|
|
|
|
|
|
|
|
public IEnumerable<GroupEntity> GetGroupsWithStudents()
|
|
|
|
|
{
|
|
|
|
|
return _groupRepository.getAllGroup().Select(
|
|
|
|
|
group => new GroupEntity()
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
Users = group.Users.Select(
|
|
|
|
|
user => new UserEntity
|
|
|
|
|
{
|
|
|
|
|
Guid = user.Guid,
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
Group = new GroupEntity
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
}
|
|
|
|
|
}).ToList()
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
2024-12-07 15:33:26 +00:00
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<GroupEntity>> GetGroupsWithStudentsAsync()
|
|
|
|
|
{
|
|
|
|
|
var result = await _groupRepository.getAllGroupAsync();
|
|
|
|
|
|
|
|
|
|
return result.Select(
|
|
|
|
|
group => new GroupEntity
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
Users = group.Users.Select(
|
|
|
|
|
user => new UserEntity
|
|
|
|
|
{
|
|
|
|
|
Guid = user.Guid,
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
Group = new GroupEntity
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
}
|
|
|
|
|
}).ToList()
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
2024-11-16 21:45:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|