xxxproject/Demo/Domain/UseCase/UseCasePresence.cs

73 lines
2.7 KiB
C#
Raw Permalink Normal View History

2024-10-30 09:11:19 +00:00
using Demo.Data.Entity;
using Demo.Data.LocalData;
2024-10-23 09:42:17 +00:00
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;
}
}
2024-10-30 09:11:19 +00:00
public void GenerateDailySchedule(int groupId, int startLesson, int endLesson, DateTime date)
2024-10-23 09:42:17 +00:00
{
var usersInGroup = LocalStaticData.users
.Where(u => u.GroupID == groupId)
.ToList();
2024-10-30 09:11:19 +00:00
LocalStaticData.presences.RemoveAll(p => usersInGroup.Select(users => users.Guid).Contains(p.UserGuid) && p.Date == DateOnly.FromDateTime(date));
2024-10-23 09:42:17 +00:00
Console.WriteLine($"Расписание для группы {groupId}:");
2024-10-30 09:11:19 +00:00
2024-10-23 09:42:17 +00:00
foreach (var user in usersInGroup)
{
2024-10-30 09:11:19 +00:00
2024-10-23 09:42:17 +00:00
for (int lesson = startLesson; lesson <= endLesson; lesson++)
{
var presence = new PresenceLocalEntity
{
UserGuid = user.Guid,
IsAttedance = true,
2024-10-30 09:11:19 +00:00
Date = DateOnly.FromDateTime(date),
2024-10-23 09:42:17 +00:00
LessonNumber = lesson
};
LocalStaticData.presences.Add(presence);
Console.WriteLine($"User: {user.Guid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}");
}
}
2024-10-30 09:11:19 +00:00
}
public void GenerateWeeklySchedule(int groupId, int startLesson, int endLesson, DateTime date)
{
for(int i = 0; i < 7;i++)
{
GenerateDailySchedule(groupId, startLesson, endLesson, date.AddDays(i));
}
2024-10-23 09:42:17 +00:00
}
}
}