using Demo.Data.RemoteData.RemoteDataBase.DAO; using Demo.Data.Repository; using Demo.Domain.UseCase; using domain.Entity; using domain.Models.ResponseModels; 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 AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents) { GroupDao groupDAO = new GroupDao { Name = addGroupWithStudents.addGroupRequest.Name }; List users = addGroupWithStudents .AddStudentRequests .Select(it => new UserDao { FIO = it.StudentName }) .ToList(); _groupRepository.AddStudents(groupDAO, users); } public async Task> GetGroupsWithStudentsAsync() { 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(); } public IEnumerable GetGroupsWithStudents() { 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() }).ToList(); } } }