using Demo.Data.Entity; using Demo.Data.LocalData; using System.Collections.Generic; using System.Linq; namespace Demo.Domain.UseCase { public class UseCasePresence { public List GetPresencesByGroupId(int groupId) { return LocalStaticData.presences .Where(p => LocalStaticData.users.Any(u => u.Guid == p.UserGuid && u.GroupID == groupId)) .ToList(); } public List 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, DateTime date) { var usersInGroup = LocalStaticData.users .Where(u => u.GroupID == groupId) .ToList(); LocalStaticData.presences.RemoveAll(p => usersInGroup.Select(users => users.Guid).Contains(p.UserGuid) && p.Date == DateOnly.FromDateTime(date)); 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(date), LessonNumber = lesson }; LocalStaticData.presences.Add(presence); Console.WriteLine($"User: {user.Guid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}"); } } } 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)); } } } }