From 5e5477477be7ce6f63d0c3d806e60a4392bfbbe4 Mon Sep 17 00:00:00 2001 From: Class_Student Date: Wed, 23 Oct 2024 12:42:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demo/Data/LocalData/Entity/Presence.cs | 2 +- Demo/Data/LocalData/LocalStaticData.cs | 44 +++++++- Demo/Data/Repository/GroupRepositoryImpl.cs | 8 +- Demo/Data/Repository/IGroupRepository.cs | 2 +- Demo/Domain/UseCase/GroupUseCase.cs | 2 +- .../Domain/UseCase/UseCaseGeneratePresence.cs | 50 +++++++++ Demo/Domain/UseCase/UseCasePresence.cs | 62 +++++++++++ Demo/Program.cs | 3 +- Demo/UI/MainMenu.cs | 66 ++++++++++-- Demo/UI/PresenceConcole.cs | 102 ++++++++++++++++++ 10 files changed, 321 insertions(+), 20 deletions(-) create mode 100644 Demo/Domain/UseCase/UseCaseGeneratePresence.cs create mode 100644 Demo/Domain/UseCase/UseCasePresence.cs create mode 100644 Demo/UI/PresenceConcole.cs diff --git a/Demo/Data/LocalData/Entity/Presence.cs b/Demo/Data/LocalData/Entity/Presence.cs index 70b8d1e..71c2474 100644 --- a/Demo/Data/LocalData/Entity/Presence.cs +++ b/Demo/Data/LocalData/Entity/Presence.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Demo.domain.Models { - internal class PresenceLocalEntity + public class PresenceLocalEntity { public required Guid UserGuid { get; set; } public bool IsAttedance { get; set; } = true; diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs index 1b904f3..5fd9fd4 100644 --- a/Demo/Data/LocalData/LocalStaticData.cs +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -11,14 +11,14 @@ namespace Demo.Data.LocalData public static class LocalStaticData { public static List groups => new List - + { new GroupLocalEntity{ Id = 1, Name = "ИП1-21" }, new GroupLocalEntity{ Id = 2, Name = "ИП1-22" }, new GroupLocalEntity{ Id = 3, Name = "ИП1-23" }, }; - - public static List users => new List + + public static List users => new List { new UserLocalEnity{Guid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "RandomFio", GroupID = 1 }, new UserLocalEnity{Guid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "RandomFio1", GroupID = 2 }, @@ -27,5 +27,43 @@ namespace Demo.Data.LocalData new UserLocalEnity{Guid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "RandomFio4", GroupID = 2 }, new UserLocalEnity{Guid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "RandomFio5", GroupID = 3 }, }; + public static List presences = new List + { + new PresenceLocalEntity { UserGuid = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + + new PresenceLocalEntity { UserGuid = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + + new PresenceLocalEntity { UserGuid = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + + new PresenceLocalEntity { UserGuid = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + + new PresenceLocalEntity { UserGuid = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + + new PresenceLocalEntity { UserGuid = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 1 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 2 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 3 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 4 }, + new PresenceLocalEntity { UserGuid = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), IsAttedance = true, Date = DateOnly.FromDateTime(DateTime.Now), LessonNumber = 5 }, + }; } } diff --git a/Demo/Data/Repository/GroupRepositoryImpl.cs b/Demo/Data/Repository/GroupRepositoryImpl.cs index a9e3818..e02cc8d 100644 --- a/Demo/Data/Repository/GroupRepositoryImpl.cs +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -48,14 +48,14 @@ namespace Demo.Data.Repository public bool AddGroup(GroupLocalEntity newGroup) { - // Проверяем, существует ли группа с таким же ID + if (GetAllGroups.Any(g => g.Id == newGroup.Id)) { - return false; // Группа с таким ID уже существует + return false; } - GetAllGroups.Add(newGroup); // Добавляем новую группу - return true; // Успешное добавление + GetAllGroups.Add(newGroup); + return true; } } } diff --git a/Demo/Data/Repository/IGroupRepository.cs b/Demo/Data/Repository/IGroupRepository.cs index e18c017..fb1d75a 100644 --- a/Demo/Data/Repository/IGroupRepository.cs +++ b/Demo/Data/Repository/IGroupRepository.cs @@ -9,7 +9,7 @@ namespace Demo.Data.Repository { public interface IGroupRepository { - bool AddGroup(GroupLocalEntity newGroup); // Убедитесь, что здесь есть только один метод + bool AddGroup(GroupLocalEntity newGroup); List GetAllGroup(); GroupLocalEntity GetGroupById(int groupID); bool RemoveGroupById(int groupID); diff --git a/Demo/Domain/UseCase/GroupUseCase.cs b/Demo/Domain/UseCase/GroupUseCase.cs index 11eddef..47e68f2 100644 --- a/Demo/Domain/UseCase/GroupUseCase.cs +++ b/Demo/Domain/UseCase/GroupUseCase.cs @@ -30,7 +30,7 @@ namespace Demo.Domain.UseCase public bool AddGroup(GroupLocalEntity group) { - // Если метод возвращает true, то группа добавлена успешно + return _repositoryGroupImpl.AddGroup(group); } diff --git a/Demo/Domain/UseCase/UseCaseGeneratePresence.cs b/Demo/Domain/UseCase/UseCaseGeneratePresence.cs new file mode 100644 index 0000000..28bd9fe --- /dev/null +++ b/Demo/Domain/UseCase/UseCaseGeneratePresence.cs @@ -0,0 +1,50 @@ +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 GenerateDailyPresence(int startLesson, int endLesson, int groupId, DateTime currentDate) + { + var users = LocalStaticData.users.Where(u => u.GroupID == groupId).ToList(); + var presences = new List(); + + 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 GenerateWeeklyPresence(int startLesson, int endLesson, int groupId, DateTime startDate) + { + var presences = new List(); + + for (int i = 0; i < 7; i++) + { + DateTime currentDate = startDate.AddDays(i); + var dailyPresences = GenerateDailyPresence(startLesson, endLesson, groupId, currentDate); + presences.AddRange(dailyPresences); + } + return presences; + } + } +} diff --git a/Demo/Domain/UseCase/UseCasePresence.cs b/Demo/Domain/UseCase/UseCasePresence.cs new file mode 100644 index 0000000..5a762fa --- /dev/null +++ b/Demo/Domain/UseCase/UseCasePresence.cs @@ -0,0 +1,62 @@ +using Demo.Data.LocalData; +using Demo.domain.Models; +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) + { + 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}"); + } + } + } + } +} diff --git a/Demo/Program.cs b/Demo/Program.cs index 42eff79..6fe09f9 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -10,7 +10,8 @@ class Program UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); + UseCasePresence presenceUseCase = new UseCasePresence(); - MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); + MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase, presenceUseCase); } } diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs index b8c21c4..089190f 100644 --- a/Demo/UI/MainMenu.cs +++ b/Demo/UI/MainMenu.cs @@ -5,16 +5,21 @@ using System; namespace Demo.UI { public class MainMenuUI - { - private UserConsoleUI _userConsoleUI; - private GroupConsoleUI _groupConsoleUI; +{ + private UserConsoleUI _userConsoleUI; + private GroupConsoleUI _groupConsoleUI; + private UseCasePresence _presenceUseCase; + private PresenceConsoleUI _presenceConsoleUI; + + public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, UseCasePresence presenceUseCase) + { + _userConsoleUI = new UserConsoleUI(userUseCase); + _groupConsoleUI = new GroupConsoleUI(groupUseCase); + _presenceUseCase = presenceUseCase; + _presenceConsoleUI = new PresenceConsoleUI(presenceUseCase); + DisplayMenu(); + } - public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase) - { - _userConsoleUI = new UserConsoleUI(userUseCase); - _groupConsoleUI = new GroupConsoleUI(groupUseCase); - DisplayMenu(); - } private void DisplayMenu() { @@ -29,6 +34,10 @@ namespace Demo.UI Console.WriteLine("6 - Добавить группу"); Console.WriteLine("7 - Обновить группу по ID"); Console.WriteLine("8 - Удалить группу по ID"); + Console.WriteLine("9 - Вывести посещаемость по группе"); + Console.WriteLine("10 - Вывести посещаемость по группе и дате"); + Console.WriteLine("11 - Отметить пользователя как отсутствующего"); + Console.WriteLine("12 - Генерация расписания по диапозону"); Console.WriteLine("0 - Выход"); var input = Console.ReadLine(); @@ -108,6 +117,45 @@ namespace Demo.UI Console.WriteLine("Некорректный ID группы."); } break; + case "9": + Console.WriteLine("Введите ID группы для отображения посещаемости:"); + string inputGroupId = Console.ReadLine(); + if (int.TryParse(inputGroupId, out int parsedGroupId)) + { + _presenceConsoleUI.DisplayPresencesByGroupId(parsedGroupId); + } + else + { + Console.WriteLine("Некорректный ID группы."); + } + break; + case "10": + Console.WriteLine("Введите ID группы для отображения посещаемости:"); + inputGroupId = Console.ReadLine(); + if (int.TryParse(inputGroupId, out parsedGroupId)) + { + Console.WriteLine("Введите дату (yyyy-MM-dd):"); + string inputDate = Console.ReadLine(); + if (DateOnly.TryParse(inputDate, out DateOnly parsedDate)) + { + _presenceConsoleUI.DisplayPresencesByGroupIdAndDate(parsedGroupId, parsedDate); + } + else + { + Console.WriteLine("Некорректная дата."); + } + } + else + { + Console.WriteLine("Некорректный ID группы."); + } + break; + case "11": + _presenceConsoleUI.MarkUserAsAbsent(); + break; + case "12": + _presenceConsoleUI.GenerateDailySchedule(); + break; case "0": return; default: diff --git a/Demo/UI/PresenceConcole.cs b/Demo/UI/PresenceConcole.cs new file mode 100644 index 0000000..ea08e58 --- /dev/null +++ b/Demo/UI/PresenceConcole.cs @@ -0,0 +1,102 @@ +using Demo.Domain.UseCase; +using System; + +namespace Demo.UI +{ + public class PresenceConsoleUI + { + private UseCasePresence _useCasePresence; + + public PresenceConsoleUI(UseCasePresence useCasePresence) + { + _useCasePresence = useCasePresence; + } + + public void DisplayPresencesByGroupId(int groupId) + { + var presences = _useCasePresence.GetPresencesByGroupId(groupId); + Console.WriteLine($"Посещаемость для группы {groupId}:"); + foreach (var presence in presences) + { + Console.WriteLine($"User: {presence.UserGuid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}"); + } + } + public void DisplayPresencesByGroupIdAndDate(int groupId, DateOnly date) + { + var presences = _useCasePresence.GetPresencesByGroupId(groupId) + .Where(p => p.Date == date) + .ToList(); + + if (presences.Count == 0) + { + Console.WriteLine($"Посещаемость отсутствует для группы {groupId} на {date.ToShortDateString()}."); + return; + } + + Console.WriteLine($"Посещаемость для группы {groupId} на {date.ToShortDateString()}:"); + foreach (var presence in presences) + { + Console.WriteLine($"User: {presence.UserGuid}, Attended: {presence.IsAttedance}, Lesson: {presence.LessonNumber}"); + } + } + public void MarkUserAsAbsent() + { + Console.WriteLine("Введите GUID пользователя:"); + if (Guid.TryParse(Console.ReadLine(), out var userGuid)) + { + Console.WriteLine("Введите номер первого занятия:"); + if (int.TryParse(Console.ReadLine(), out int startLesson)) + { + Console.WriteLine("Введите номер последнего занятия:"); + if (int.TryParse(Console.ReadLine(), out int endLesson)) + { + _useCasePresence.MarkUserAsAbsent(userGuid, startLesson, endLesson); + Console.WriteLine("Пользователь отмечен как отсутствующий."); + } + else + { + Console.WriteLine("Некорректный номер последнего занятия."); + } + } + else + { + Console.WriteLine("Некорректный номер первого занятия."); + } + } + else + { + Console.WriteLine("Некорректный GUID."); + } + } + public void GenerateDailySchedule() + { + Console.WriteLine("Введите ID группы:"); + if (int.TryParse(Console.ReadLine(), out int groupId)) + { + Console.WriteLine("Введите номер первого урока:"); + if (int.TryParse(Console.ReadLine(), out int startLesson)) + { + Console.WriteLine("Введите номер последнего урока:"); + if (int.TryParse(Console.ReadLine(), out int endLesson)) + { + _useCasePresence.GenerateDailySchedule(groupId, startLesson, endLesson); + } + else + { + Console.WriteLine("Некорректный номер последнего урока."); + } + } + else + { + Console.WriteLine("Некорректный номер первого урока."); + } + } + else + { + Console.WriteLine("Некорректный ID группы."); + } + } + + + } +}