using data.Repository; using Demo.Data.RemoteData.RemoteDataBase.DAO; using Demo.Data.Repository; using domain.Models.ResponseModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace domain.UseCase { public class AdminUseCase { private readonly IAdminRepository _adminRepository; private readonly IGroupRepository _groupRepository; public AdminUseCase(IAdminRepository adminRepository, IGroupRepository groupRepository) { _adminRepository = adminRepository; _groupRepository = groupRepository; } public IEnumerable GetAllGroupsWithStudents() => _adminRepository.GetAllGroupsWithStudents().Select(it => new GroupResponse { Name = it.Name, Id = it.Id, User = it.Users.Where(u => u.GroupId == it.Id) .Select(u => new UserResponse { Id = u.UserId, FIO = u.FIO }) .ToList() }) .ToList(); public UserResponse GetStudentInfo(int userId) { var studentInfo = _adminRepository.GetStudentInfo(userId); if (studentInfo == null) return null; UserResponse user = new UserResponse { Id = userId, FIO = _adminRepository.GetStudentInfo(userId).FIO, GroupId = _adminRepository.GetStudentInfo(userId).GroupId }; return user; } public bool AddStudents(string GroupName, List Students) { GroupDao groupDao = new GroupDao { Name = GroupName }; return _adminRepository.AddStudents(groupDao, Students); } public bool DeleteGroup(int groupId) => _groupRepository.RemoveGroupById(groupId); public bool DeleteUserFromGroup(int userId, int groupId) => _adminRepository.RemoveUserById(userId, groupId); } }