110 lines
3.4 KiB
C#
110 lines
3.4 KiB
C#
using data.DAO;
|
|
using data.Repository;
|
|
using domain.Entity;
|
|
using domain.Request;
|
|
using domain.UseCase;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace domain.Service
|
|
{
|
|
public class PresenceService : IPresenceUseCase
|
|
{
|
|
private readonly IPresenceRepository _presenceRepository;
|
|
|
|
public PresenceService(IPresenceRepository presenceRepository)
|
|
{
|
|
_presenceRepository = presenceRepository;
|
|
}
|
|
|
|
public IEnumerable<PresenceEntity> GetPresence(
|
|
int groupId,
|
|
int? subjectId = null,
|
|
DateOnly? date = null,
|
|
int? studentId = null)
|
|
{
|
|
return _presenceRepository.GetPresence(groupId, subjectId, date, studentId).Select(p => new PresenceEntity
|
|
{
|
|
Id = p.Id,
|
|
StudentId = p.Student.Id,
|
|
Student = new UserEntity
|
|
{
|
|
Id = p.Student.Id,
|
|
FirstName = p.Student.FirstName,
|
|
LastName = p.Student.LastName,
|
|
Patronymic = p.Student.Patronymic,
|
|
Group = new GroupEntity()
|
|
},
|
|
SubjectId = p.StudentGroupSubject.Subject.Id,
|
|
Subject = new SubjectEntity
|
|
{
|
|
Id = p.StudentGroupSubject.Subject.Id,
|
|
Name = p.StudentGroupSubject.Subject.Name
|
|
},
|
|
TrafficId = p.TrafficId,
|
|
Traffic = new TrafficEntity
|
|
{
|
|
Id = p.TrafficId,
|
|
Name = p.Traffic.Name
|
|
},
|
|
LessonNumber = p.NumberSubject,
|
|
Date = p.Date
|
|
});
|
|
}
|
|
|
|
public void DeleteAllPresence()
|
|
{
|
|
_presenceRepository.DeleteAllPresence();
|
|
}
|
|
|
|
public void DeleteGroupPresence(int groupId)
|
|
{
|
|
_presenceRepository.DeleteGroupPresence(groupId);
|
|
}
|
|
|
|
public void AddPresenceRecords(AddPresenceRequest request)
|
|
{
|
|
if (request?.Items == null || request.Items.Count == 0)
|
|
throw new ArgumentException("No records");
|
|
|
|
List<Diary> diaries = new List<Diary>();
|
|
|
|
foreach (var item in request.Items)
|
|
{
|
|
diaries.Add(new Diary
|
|
{
|
|
Date = item.Date,
|
|
DiaryText = "",
|
|
NumberSubject = item.LessonNumber,
|
|
StudentId = item.StudentId,
|
|
TrafficId = item.TrafficId,
|
|
StudentGroupSubjectId = item.StudentGroupSubjectId
|
|
});
|
|
}
|
|
|
|
_presenceRepository.AddPresenceRecords(diaries);
|
|
}
|
|
|
|
public void UpdatePresenceRecords(UpdatePresenceRequest request)
|
|
{
|
|
if (request?.Items == null || request.Items.Count == 0)
|
|
throw new ArgumentException("No records");
|
|
|
|
List<Diary> diaries = new List<Diary>();
|
|
|
|
foreach (var item in request.Items)
|
|
{
|
|
diaries.Add(new Diary
|
|
{
|
|
Date = item.Date,
|
|
NumberSubject = item.LessonNumber,
|
|
StudentId = item.StudentId,
|
|
TrafficId = item.TrafficId,
|
|
});
|
|
}
|
|
|
|
_presenceRepository.UpdatePresenceRecords(diaries);
|
|
}
|
|
}
|
|
}
|