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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 07:36:11 +00:00
|
|
|
|
public bool AddGroup(AddGroupRequest addGroupRequest)
|
2024-11-26 05:09:12 +00:00
|
|
|
|
=> _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
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 07:36:11 +00:00
|
|
|
|
public bool RemoveGroup(RemoveGroupRequest removeGroupRequest)
|
2024-11-26 05:09:12 +00:00
|
|
|
|
=> _groupRepository.DeleteGroup(removeGroupRequest.GroupId);
|
2024-12-04 12:21:15 +00:00
|
|
|
|
|
|
|
|
|
public GroupSubjectEntity GetGroupSubject(int id)
|
|
|
|
|
{
|
|
|
|
|
return _groupRepository.GetAllGroups().Select(
|
|
|
|
|
group => new GroupSubjectEntity
|
|
|
|
|
{
|
|
|
|
|
Id = group.Id,
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
Subjects = group.StudentGroupsSubjects.Select(
|
|
|
|
|
subject => new SubjectEntity
|
|
|
|
|
{
|
|
|
|
|
Id = subject.Subject.Id,
|
|
|
|
|
Name = subject.Subject.Name,
|
|
|
|
|
})
|
|
|
|
|
}).Single(g => g.Id == id);
|
|
|
|
|
}
|
2024-11-26 05:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|