2024-12-19 17:36:57 +00:00
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
2024-12-05 09:30:01 +00:00
|
|
|
|
using Demo.Data.Repository;
|
2024-12-19 17:36:57 +00:00
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
using domain.Entity;
|
|
|
|
|
using domain.Models.ResponseModels;
|
|
|
|
|
using domain.Request;
|
2024-12-05 09:30:01 +00:00
|
|
|
|
using domain.UseCase;
|
2024-12-19 17:36:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-12-05 09:30:01 +00:00
|
|
|
|
|
|
|
|
|
namespace domain.Service
|
|
|
|
|
{
|
|
|
|
|
public class GroupService : IGroupUseCase
|
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
private readonly IGroupRepository _groupRepository;
|
|
|
|
|
public GroupService(IGroupRepository groupRepository)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
_groupRepository = groupRepository;
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public void AddGroup(AddGroupRequest addGroupRequest)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
_groupRepository.AddGroup(new GroupDao { Name = addGroupRequest.Name });
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public void AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
GroupDao groupDAO = new GroupDao { Name = addGroupWithStudents.addGroupRequest.Name };
|
|
|
|
|
List<UserDao> users = addGroupWithStudents
|
|
|
|
|
.AddStudentRequests
|
|
|
|
|
.Select(it => new UserDao { FIO = it.StudentName })
|
|
|
|
|
.ToList();
|
|
|
|
|
_groupRepository.AddStudents(groupDAO, users);
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public async Task<IEnumerable<GroupResponse>> GetGroupsWithStudentsAsync()
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
var result = await _groupRepository.getAllGroupAsync();
|
|
|
|
|
|
|
|
|
|
return result.Select(
|
|
|
|
|
group => new GroupResponse
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
User = group.Users.Select(
|
|
|
|
|
user => new UserResponse
|
|
|
|
|
{
|
|
|
|
|
Id = user.UserId,
|
|
|
|
|
FIO = user.FIO,
|
|
|
|
|
Group = new GroupResponse
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
}
|
|
|
|
|
}).ToList()
|
|
|
|
|
}).ToList();
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public IEnumerable<GroupResponse> GetGroupsWithStudents()
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-19 17:36:57 +00:00
|
|
|
|
return _groupRepository.GetAllGroup().Select(
|
|
|
|
|
group => new GroupResponse
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
User = group.Users != null ? group.Users.Select(
|
|
|
|
|
user => new UserResponse
|
|
|
|
|
{
|
|
|
|
|
Id = user.UserId,
|
|
|
|
|
FIO = user.FIO,
|
|
|
|
|
Group = new GroupResponse
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
}
|
|
|
|
|
}).ToList() : new List<UserResponse>()
|
|
|
|
|
}).ToList();
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-19 17:36:57 +00:00
|
|
|
|
}
|