84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
|
using data.Repository;
|
||
|
using domain.Models.ResponseModels;
|
||
|
using domain.Requests;
|
||
|
using domain.UseCase;
|
||
|
using presence.data.RemoteData.RemoteDataBase.DAO;
|
||
|
using presence.data.Repository;
|
||
|
using presence.domain.Models;
|
||
|
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.AddGroup(new GroupDao { Name = addGroupRequest.Name });
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudents)
|
||
|
{
|
||
|
GroupDao groupDAO = new GroupDao { Name = addGroupWithStudents.addGroupRequest.Name };
|
||
|
List<UserDao> users = addGroupWithStudents
|
||
|
.AddStudentRequests
|
||
|
.Select(it => new UserDao { FIO = it.StudentName })
|
||
|
.ToList();
|
||
|
_groupRepository.AddStudents(groupDAO, users);
|
||
|
}
|
||
|
|
||
|
public async Task<IEnumerable<GroupResponse>> GetGroupsWithStudentsAsync()
|
||
|
{
|
||
|
var result = await _groupRepository.getAllGroupAsync();
|
||
|
|
||
|
return result.Select(
|
||
|
group => new GroupResponse
|
||
|
{
|
||
|
Id = group.Id,
|
||
|
Name = group.Name,
|
||
|
User = group.User.Select(
|
||
|
user => new UserResponse
|
||
|
{
|
||
|
Id = user.UserId,
|
||
|
FIO = user.FIO,
|
||
|
Group = new GroupResponse
|
||
|
{
|
||
|
Id = group.Id,
|
||
|
Name = group.Name,
|
||
|
}
|
||
|
}).ToList()
|
||
|
}).ToList();
|
||
|
}
|
||
|
|
||
|
public IEnumerable<GroupResponse> GetGroupsWithStudents()
|
||
|
{
|
||
|
return _groupRepository.GetAllGroup().Select(
|
||
|
group => new GroupResponse
|
||
|
{
|
||
|
Id = group.Id,
|
||
|
Name = group.Name,
|
||
|
User = group.User != null ? group.User.Select(
|
||
|
user => new UserResponse
|
||
|
{
|
||
|
Id = user.UserId,
|
||
|
FIO = user.FIO,
|
||
|
Group = new GroupResponse
|
||
|
{
|
||
|
Id = group.Id,
|
||
|
Name = group.Name,
|
||
|
}
|
||
|
}).ToList() : new List<UserResponse>()
|
||
|
}).ToList();
|
||
|
}
|
||
|
}
|
||
|
}
|