63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
|
using Demo.Data.LocalData;
|
|||
|
using Demo.domain.Models;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace Demo.Domain.UseCase
|
|||
|
{
|
|||
|
public class UseCasePresence
|
|||
|
{
|
|||
|
public List<PresenceLocalEntity> GetPresencesByGroupId(int groupId)
|
|||
|
{
|
|||
|
return LocalStaticData.presences
|
|||
|
.Where(p => LocalStaticData.users.Any(u => u.Guid == p.UserGuid && u.GroupID == groupId))
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
|
|||
|
public List<PresenceLocalEntity> GetPresencesByGroupIdAndDate(int groupId, DateOnly date)
|
|||
|
{
|
|||
|
return LocalStaticData.presences
|
|||
|
.Where(p => LocalStaticData.users.Any(u => u.Guid == p.UserGuid && u.GroupID == groupId)
|
|||
|
&& p.Date == date)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public void MarkUserAsAbsent(Guid userGuid, int startLesson, int endLesson)
|
|||
|
{
|
|||
|
var presences = LocalStaticData.presences
|
|||
|
.Where(p => p.UserGuid == userGuid && p.LessonNumber >= startLesson && p.LessonNumber <= endLesson)
|
|||
|
.ToList();
|
|||
|
|
|||
|
foreach (var presence in presences)
|
|||
|
{
|
|||
|
presence.IsAttedance = false;
|
|||
|
}
|
|||
|
}
|
|||
|
public void GenerateDailySchedule(int groupId, int startLesson, int endLesson)
|
|||
|
{
|
|||
|
var usersInGroup = LocalStaticData.users
|
|||
|
.Where(u => u.GroupID == groupId)
|
|||
|
.ToList();
|
|||
|
|
|||
|
Console.WriteLine($"Расписание для группы {groupId}:");
|
|||
|
|
|||
|
foreach (var user in usersInGroup)
|
|||
|
{
|
|||
|
for (int lesson = startLesson; lesson <= endLesson; lesson++)
|
|||
|
{
|
|||
|
var presence = new PresenceLocalEntity
|
|||
|
{
|
|||
|
UserGuid = user.Guid,
|
|||
|
IsAttedance = true,
|
|||
|
Date = DateOnly.FromDateTime(DateTime.Now),
|
|||
|
LessonNumber = lesson
|
|||
|
};
|
|||
|
|
|||
|
LocalStaticData.presences.Add(presence);
|
|||
|
|
|||
|
Console.WriteLine($"User: {user.Guid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|