xxxproject/Demo/Domain/UseCase/UseCaseGeneratePresence.cs

51 lines
1.7 KiB
C#
Raw Normal View History

2024-10-23 09:42:17 +00:00
using Demo.Data.LocalData;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Domain.UseCase
{
public class UseCaseGeneratePresence
{
public List<Presence> GenerateDailyPresence(int startLesson, int endLesson, int groupId, DateTime currentDate)
{
var users = LocalStaticData.users.Where(u => u.GroupID == groupId).ToList();
var presences = new List<Presence>();
for (int lesson = startLesson; lesson <= endLesson; lesson++)
{
foreach (var user in users)
{
presences.Add(new Presence
{
User = new User
{
Guid = user.Guid,
FIO = user.FIO,
Group = new Group { Id = groupId, Name = LocalStaticData.groups.First(g => g.Id == groupId).Name }
},
Date = DateOnly.FromDateTime(currentDate),
LessonNumber = lesson,
IsAttedance = true
});
}
}
return presences;
}
public List<Presence> GenerateWeeklyPresence(int startLesson, int endLesson, int groupId, DateTime startDate)
{
var presences = new List<Presence>();
for (int i = 0; i < 7; i++)
{
DateTime currentDate = startDate.AddDays(i);
var dailyPresences = GenerateDailyPresence(startLesson, endLesson, groupId, currentDate);
presences.AddRange(dailyPresences);
}
return presences;
}
}
}