presence/domain/Service/GroupService.cs

67 lines
2.3 KiB
C#
Raw Normal View History

2024-11-26 05:09:12 +00:00
using data.DAO;
using data.Repository;
using domain.Entity;
using domain.Request;
using domain.UseCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace domain.Service
{
public class GroupService : IGroupUseCase
{
private readonly IGroupRepository _groupRepository;
public GroupService(IGroupRepository groupRepository)
{
_groupRepository = groupRepository;
}
public void AddGroup(AddGroupRequest addGroupRequest)
=> _groupRepository.CreateGroup(new Group { Name = addGroupRequest.Name });
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudentRequest)
{
Group group = new Group { Name = addGroupWithStudentRequest.AddGroupRequest.Name };
List<Student> students = addGroupWithStudentRequest
.AddStudentRequests
.Select(it => new Student { FirstName = it.FirstName, LastName = it.LastName, Patronymic = it.Patronymic})
.ToList();
_groupRepository.AddGroupWithStudents(group, students);
}
public void EditGroup(EditGroupRequest editGroupRequest)
=> _groupRepository.UpdateGroup(editGroupRequest.GroupId, editGroupRequest.GroupName);
public IEnumerable<GroupEntity> GetGroupsWithStudents()
{
return _groupRepository.GetAllGroups().Select(
group => new GroupEntity
{
Id = group.Id,
Name = group.Name,
Users = group.Students.Select(
user => new UserEntity
{
Id = user.Id,
LastName = user.LastName,
FirstName = user.FirstName,
Patronymic = user.Patronymic,
Group = new GroupEntity
{
Id = group.Id,
Name = group.Name
}
})
});
}
public void RemoveGroup(RemoveGroupRequest removeGroupRequest)
=> _groupRepository.DeleteGroup(removeGroupRequest.GroupId);
}
}