2024-11-18 22:12:53 +00:00
|
|
|
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;
|
|
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public AdminUseCase(IAdminRepository adminRepository, IGroupRepository groupRepository, IUserRepository userRepository)
|
|
|
|
{
|
|
|
|
_adminRepository = adminRepository;
|
|
|
|
_groupRepository = groupRepository;
|
|
|
|
_userRepository = userRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<GroupResponse> 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)
|
|
|
|
{
|
2024-11-19 12:41:31 +00:00
|
|
|
|
|
|
|
var studentInfo = _adminRepository.GetStudentInfo(userId);
|
|
|
|
if (studentInfo == null) return null;
|
|
|
|
|
2024-11-18 22:12:53 +00:00
|
|
|
UserResponse user= new UserResponse{
|
|
|
|
Id = userId,
|
|
|
|
FIO = _adminRepository.GetStudentInfo(userId).FIO,
|
|
|
|
GroupId = _adminRepository.GetStudentInfo(userId).GroupId
|
|
|
|
};
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool AddStudents(string GroupName, List<string> 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|