57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
|
using data.RemoteData.RemoteDataBase.DAO;
|
|||
|
using data.Repository;
|
|||
|
using domain.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|