using data.DAO; using data.Repository; using domain.Entity; 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 GroupDAO { Name = addGroupRequest.Name }); } public void AddGroupWithSutdents(AddGroupWithStudentsRequest addGroupWithStudents) { GroupDAO groupDAO = new GroupDAO { Name = addGroupWithStudents.addGroupRequest.Name }; List users = addGroupWithStudents .AddStudentRequests .Select(it => new UserDAO { Name = it.StudentName }) .ToList(); _groupRepository.addGroupWithStudents(groupDAO, users); } public IEnumerable 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(); } } }