presence_new/domain/UseCase/AdminUseCase.cs

71 lines
2.3 KiB
C#
Raw Normal View History

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;
2024-12-05 06:55:28 +00:00
public AdminUseCase(IAdminRepository adminRepository, IGroupRepository groupRepository)
{
_adminRepository = adminRepository;
_groupRepository = groupRepository;
}
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;
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};
2024-12-13 07:21:14 +00:00
List<UserDao> users = new List<UserDao>();
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);
}
}