using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using data.Repository; using domain.Models.ResponseModels; using presence.data.RemoteData.RemoteDataBase.DAO; using presence.data.Repository; 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.User.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}; List users = new List(); foreach (string student in Students) { var user = new UserDao { FIO = student, Group = groupDao }; users.Add(user); } return _adminRepository.AddStudents(groupDao, users); } public bool DeleteGroup(int groupId) => _groupRepository.RemoveGroupById(groupId); public bool DeleteUserFromGroup(int userId, int groupId) => _adminRepository.RemoveUserById(userId, groupId); } }