53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Controller.Repository;
|
|
using Controller.ViewModels;
|
|
using DataModels.Models;
|
|
|
|
namespace Controller.BusinessLogic
|
|
{
|
|
public class GroupLogic
|
|
{
|
|
private readonly SpecializationRepository _specializationRepository;
|
|
private readonly GroupRepository _groupRepository;
|
|
public GroupLogic(SpecializationRepository rep, GroupRepository groupRepository)
|
|
{
|
|
_specializationRepository = rep;
|
|
_groupRepository = groupRepository;
|
|
}
|
|
|
|
public async Task<List<GroupViewModel>> GetViewModel()
|
|
{
|
|
//var groups = await _groupRepository.GetAll();
|
|
|
|
//var specialization = student.SpecializationId.HasValue
|
|
// ? await _specializationRepository.Get(group.SpecializationId.Value) : null;
|
|
|
|
var specs = new List<Specialization>
|
|
{
|
|
new Specialization{Id = 1, Code = "1234", Name = "Программная инженерия"},
|
|
new Specialization{Id = 2, Code = "5678", Name = "Информатика"},
|
|
|
|
};
|
|
|
|
var groups = new List<Group>
|
|
{
|
|
new Group{Id = 1, Course = 3, Name = "ПИ", Number = 1, CountStudents = 29, SpecializationId = 1},
|
|
new Group{Id = 2, Course = 3, Name = "ПМ", Number = 4, CountStudents = 24, SpecializationId = 2},
|
|
|
|
};
|
|
|
|
var results = new List<GroupViewModel>();
|
|
|
|
foreach (var group in groups)
|
|
{
|
|
var spec = group.SpecializationId.HasValue
|
|
? specs.FirstOrDefault(s => s.Id == group.SpecializationId.Value)
|
|
: group?.SpecializationId != null
|
|
? specs.FirstOrDefault(s => s.Id == group.SpecializationId)
|
|
: null;
|
|
results.Add(new GroupViewModel(group, spec));
|
|
}
|
|
return results;
|
|
}
|
|
}
|
|
}
|