presence_new/domain/UseCase/AdminUseCase.cs

59 lines
2.0 KiB
C#

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)
{
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);
}
}