Presence_Desktop/domain/UseCase/UseCaseAPI.cs
2024-12-23 14:20:09 +03:00

49 lines
1.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using data.RemoteData.DAO;
using data.Repository;
using domain.Models;
namespace domain.UseCase
{
public class UseCaseAPI
{
public readonly IUserRepository _userRepository;
public readonly IPresenceRepository _presenceRepository;
private readonly IGroupRepository _groupRepository;
public UseCaseAPI(IUserRepository userRepository, IPresenceRepository presenceRepository, IGroupRepository groupRepository)
{
_userRepository = userRepository;
_presenceRepository = presenceRepository;
_groupRepository = groupRepository;
}
public void AddGroupWithStudents(GroupWithStudentsDto groupDto)
{
if (string.IsNullOrWhiteSpace(groupDto.GroupName))
throw new ArgumentException("Название группы не может быть пустым.");
// Создаем группу
var newGroup = new GroupDao
{
Name = groupDto.GroupName
};
// Сохраняем группу и получаем ее ID
int groupId = _groupRepository.AddGroup(newGroup);
// Если есть пользователи, добавляем их
foreach (var studentFio in groupDto.Students)
{
var user = new UserDao
{
FIO = studentFio,
GroupID = groupId,
Guid = Guid.NewGuid() // Генерация нового GUID
};
_userRepository.AddUser(user);
}
}
}
}