commit be7c0f9372376acdb7e75bbec5f76ec6781e1c94 Author: Nastya Date: Fri Oct 25 23:08:16 2024 +0300 final diff --git a/Demo.sln b/Demo.sln new file mode 100644 index 0000000..ce1f93c --- /dev/null +++ b/Demo.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "Demo\Demo.csproj", "{983820F6-FF31-4B3A-8593-831BC3904E80}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {983820F6-FF31-4B3A-8593-831BC3904E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {983820F6-FF31-4B3A-8593-831BC3904E80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {983820F6-FF31-4B3A-8593-831BC3904E80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {983820F6-FF31-4B3A-8593-831BC3904E80}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4F43A963-447C-4FCB-BB78-8D315EC0F1D6} + EndGlobalSection +EndGlobal diff --git a/Demo/Data/Entity/Group.cs b/Demo/Data/Entity/Group.cs new file mode 100644 index 0000000..6041311 --- /dev/null +++ b/Demo/Data/Entity/Group.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + public class GroupLocalEntity + { + public required int Id { get; set; } + public required string Name { get; set; } + + } +} diff --git a/Demo/Data/Entity/Presence.cs b/Demo/Data/Entity/Presence.cs new file mode 100644 index 0000000..70b8d1e --- /dev/null +++ b/Demo/Data/Entity/Presence.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + internal class PresenceLocalEntity + { + public required Guid UserGuid { get; set; } + public bool IsAttedance { get; set; } = true; + public required DateOnly Date { get; set; } + + public required int LessonNumber { get; set; } + } +} diff --git a/Demo/Data/Entity/User.cs b/Demo/Data/Entity/User.cs new file mode 100644 index 0000000..5af4881 --- /dev/null +++ b/Demo/Data/Entity/User.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + public class UserLocalEnity : IEquatable + { + public required string FIO { get; set; } + public Guid Guid { get; set; } + + public required int GroupID { get; set; } + + + + public bool Equals(UserLocalEnity? other) + { + if (other == null) return false; + return this.Guid.Equals(other.Guid); + } + } +} diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs new file mode 100644 index 0000000..50e54f7 --- /dev/null +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -0,0 +1,31 @@ +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +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 + { + 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 }, + new UserLocalEnity{Guid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "RandomFio2", GroupID = 3 }, + new UserLocalEnity{Guid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "RandomFio3", GroupID = 1 }, + 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 }, + }; + } +} diff --git a/Demo/Data/Repository/GroupRepositoryImpl.cs b/Demo/Data/Repository/GroupRepositoryImpl.cs new file mode 100644 index 0000000..476dd67 --- /dev/null +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -0,0 +1,40 @@ +using Demo.Data.LocalData; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Data.Repository +{ + public class GroupRepositoryImpl : IGroupRepository + { + public bool AddGroup(GroupLocalEntity newGroup) + { + throw new NotImplementedException(); + } + + public List GetAllGroup() + { + throw new NotImplementedException(); + } + + public List GetAllGroups() => LocalStaticData.groups; + + public GroupLocalEntity GetGroupById(int groupID) + { + throw new NotImplementedException(); + } + + public bool RemoveGroupById(int groupID) + { + throw new NotImplementedException(); + } + + public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Demo/Data/Repository/IGroupRepository.cs b/Demo/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..610efde --- /dev/null +++ b/Demo/Data/Repository/IGroupRepository.cs @@ -0,0 +1,18 @@ +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Data.Repository +{ + public interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); + GroupLocalEntity GetGroupById(int groupID); + bool AddGroup(GroupLocalEntity newGroup); + } +} diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs new file mode 100644 index 0000000..bf9ae8c --- /dev/null +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -0,0 +1,47 @@ +using Demo.Data.LocalData; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Data.Repository +{ + public class UserRepositoryImpl + { + public UserRepositoryImpl() { + + GetAllUsers = LocalStaticData.users; + } + public List GetAllUsers + { get; set; } + + public bool RemoveUserByGuid(Guid userGuid) + { + UserLocalEnity? userLocal = GetAllUsers + .Where(x => x.Guid == userGuid).FirstOrDefault(); + if (userLocal == null) return false; + + return GetAllUsers.Remove(userLocal); + } + + public UserLocalEnity? GetUserByGuid(Guid userGuid) { + UserLocalEnity? userLocal = GetAllUsers + .Where(x => x.Guid == userGuid).FirstOrDefault(); + if (userLocal == null) return null; + + return userLocal; + } + + public UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity) { + UserLocalEnity? userLocal = GetAllUsers + .Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault(); + if (userLocal == null) return null; + userLocal.FIO = userUpdateLocalEnity.FIO; + userLocal.GroupID = userUpdateLocalEnity.GroupID; + return userLocal; + + } + } +} diff --git a/Demo/Domain/Models/Group.cs b/Demo/Domain/Models/Group.cs new file mode 100644 index 0000000..ce0914b --- /dev/null +++ b/Demo/Domain/Models/Group.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + public class Group + { + public required int Id { get; set; } + public required string Name { get; set; } + } +} diff --git a/Demo/Domain/Models/Presence.cs b/Demo/Domain/Models/Presence.cs new file mode 100644 index 0000000..a5fe7a0 --- /dev/null +++ b/Demo/Domain/Models/Presence.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + public class Presence + { + + public required User User { get; set; } + public bool IsAttedance { get; set; } = true; + public required DateOnly Date { get; set; } + + public required int LessonNumber { get; set; } + } +} diff --git a/Demo/Domain/Models/User.cs b/Demo/Domain/Models/User.cs new file mode 100644 index 0000000..cffca41 --- /dev/null +++ b/Demo/Domain/Models/User.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.domain.Models +{ + public class User + { + public required string FIO { get; set; } + public Guid Guid { get; set; } + + public required Group Group { get; set; } + } +} diff --git a/Demo/Domain/Presence/UseCaseGeneratePresence.cs b/Demo/Domain/Presence/UseCaseGeneratePresence.cs new file mode 100644 index 0000000..7b7a15e --- /dev/null +++ b/Demo/Domain/Presence/UseCaseGeneratePresence.cs @@ -0,0 +1,64 @@ +using Demo.Data.LocalData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Domain.Presence +{ + + public class UseCaseGeneratePresence + { + public List GenerateDailyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime currentDate) + { + List attendanceRecords = new List(); + + // Проверка на корректность входных данных + if (firstLesson < 1 || lastLesson < firstLesson) + { + throw new ArgumentException("Неверные номера уроков."); + } + + for (int lesson = firstLesson; lesson <= lastLesson; lesson++) + { + attendanceRecords.Add(new AttendanceRecord + { + LessonNumber = lesson, + GroupNumber = groupNumber, + Date = currentDate, + IsPresent = true + }); + } + + return attendanceRecords; + } + + public List GenerateWeeklyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime startDate) + { + List weeklyAttendanceRecords = new List(); + + // Проверка на корректность входных данных + if (firstLesson < 1 || lastLesson < firstLesson) + { + throw new ArgumentException("Неверные номера уроков."); + } + + for (int day = 0; day < 7; day++) + { + DateTime currentDate = startDate.AddDays(day); + weeklyAttendanceRecords.AddRange(GenerateDailyAttendance(firstLesson, lastLesson, groupNumber, currentDate)); + } + + return weeklyAttendanceRecords; + } + + public class AttendanceRecord + { + public int LessonNumber { get; set; } + public string GroupNumber { get; set; } + public DateTime Date { get; set; } + public bool IsPresent { get; set; } + } + } +} \ No newline at end of file diff --git a/Demo/Domain/UseCase/GroupUseCase.cs b/Demo/Domain/UseCase/GroupUseCase.cs new file mode 100644 index 0000000..39fcd30 --- /dev/null +++ b/Demo/Domain/UseCase/GroupUseCase.cs @@ -0,0 +1,42 @@ +using Demo.Data.LocalData; +using Demo.Data.Repository; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Demo.Domain.UseCase +{ + public class GroupUseCase + { + private List _groups = LocalStaticData.groups; // вывести все группы + + public List GetAllGroups() => _groups; + + public void AddGroup(GroupLocalEntity group) //добавить группу + { + group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1; + _groups.Add(group); + } + public void RenameGroup(int groupId, string newName) //переименовать группу + { + if (string.IsNullOrWhiteSpace(newName)) + { + throw new ArgumentException("Новое имя группы не может быть пустым", nameof(newName)); + } + + var existingGroup = _groups.FirstOrDefault(g => g.Id == groupId); + if (existingGroup == null) + { + throw new KeyNotFoundException($"Группа с ID {groupId} не найдена."); + } + existingGroup.Name = newName; + } + + } +} + + diff --git a/Demo/Domain/UseCase/UseCasePresence.cs b/Demo/Domain/UseCase/UseCasePresence.cs new file mode 100644 index 0000000..e63f8d4 --- /dev/null +++ b/Demo/Domain/UseCase/UseCasePresence.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Domain.UseCase +{ + public class UseCasePresence + { + private Dictionary> attendanceRecords; + + public UseCasePresence() + { + attendanceRecords = new Dictionary>(); + } + + public void MarkAttendance(string group, DateTime date) + { + if (!attendanceRecords.ContainsKey(group)) + { + attendanceRecords[group] = new List(); + } + attendanceRecords[group].Add(date); + } + + public List GetAttendanceByGroup(string group) + { + if (attendanceRecords.ContainsKey(group)) + { + return attendanceRecords[group]; + } + return new List(); + } + + public List GetAttendanceByGroupAndDate(string group, DateTime date) + { + if (attendanceRecords.ContainsKey(group)) + { + return attendanceRecords[group].Where(d => d.Date == date.Date).ToList(); + } + return new List(); + } + + public void MarkUserAsAbsent(string group, DateTime startDate, DateTime endDate) + { + if (attendanceRecords.ContainsKey(group)) + { + for (DateTime date = startDate; date <= endDate; date = date.AddDays(1)) + { + attendanceRecords[group].Remove(date); + } + } + } + } +} \ No newline at end of file diff --git a/Demo/Domain/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs new file mode 100644 index 0000000..9ddc215 --- /dev/null +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -0,0 +1,65 @@ +using Demo.Data.Repository; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.Domain.UseCase +{ + public class UserUseCase + { + private UserRepositoryImpl _repositoryUserImpl; + private GroupRepositoryImpl _repositoryGroupImpl; + + public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) + { + _repositoryUserImpl = repositoryImpl; + _repositoryGroupImpl = repositoryGroupImpl; + } + + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + .Select(it => new Group { Id = it.Id, Name = it.Name }).ToList(); + public List GetAllUsers() => _repositoryUserImpl.GetAllUsers + .Join(_repositoryGroupImpl.GetAllGroups(), + user => user.GroupID, + group => group.Id, + (user, group) => + new User + { + FIO = user.FIO, + Guid = user.Guid, + Group = new Group { Id = group.Id, Name = group.Name } + } + ).ToList(); + + public bool RemoveUserByGuid(Guid userGuid) + { + return _repositoryUserImpl.RemoveUserByGuid(userGuid); + } + public User UpdateUser(User user) + { + UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; + UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); + if (result == null) throw new Exception(""); + Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID); + if (group == null) throw new Exception(""); + return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; + } + public User FindUserByGuid(Guid userGuid) + { + Dictionary users = new Dictionary(); + + if (users.ContainsKey(userGuid)) + { + return users[userGuid]; + } + else + { + return null; + } + + } + } +} \ No newline at end of file diff --git a/Demo/Program.cs b/Demo/Program.cs new file mode 100644 index 0000000..48611a5 --- /dev/null +++ b/Demo/Program.cs @@ -0,0 +1,10 @@ + +using Demo.Data.Repository; +using Demo.Domain.UseCase; +using Demo.UI; + +GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); +UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); +UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); + +MainMenuUI mainMenuUI = new MainMenuUI(userUseCase); diff --git a/Demo/UI/GroupConsole.cs b/Demo/UI/GroupConsole.cs new file mode 100644 index 0000000..772f2c6 --- /dev/null +++ b/Demo/UI/GroupConsole.cs @@ -0,0 +1,44 @@ +using Demo.domain.Models; +using Demo.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.UI +{ + public class GroupConsole + { + + + internal class GroupConsoleUI + { + GroupUseCase _groupUseCase; + + public GroupConsoleUI(GroupUseCase groupUseCase) + { + _groupUseCase = groupUseCase; + } + + + public void AllGroups() + { + foreach (var Group in _groupUseCase.GetAllGroups()) + { + Console.WriteLine($"{Group.Id}\t{Group.Name}"); + } + } + + public void UpdateGroup(int groupId, GroupLocalEntity updatedGroup) + { + if (updatedGroup == null) + { + throw new ArgumentNullException(nameof(updatedGroup), "Обновленная группа не может быть null"); + } + + + } + } + } +} diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs new file mode 100644 index 0000000..4f867ef --- /dev/null +++ b/Demo/UI/MainMenu.cs @@ -0,0 +1,67 @@ +using Demo.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.UI +{ + public class MainMenuUI + { + private UserConsoleUI _userConsoleUI; + + public MainMenuUI(UserUseCase userUseCase) + { + _userConsoleUI = new UserConsoleUI(userUseCase); + DisplayMenu(); + } + + private void DisplayMenu() + { + while (true) + { + Console.Clear(); + Console.WriteLine("Главное меню:"); + Console.WriteLine("1. Показать всех пользователей"); + Console.WriteLine("2. Удалить пользователя по GUID"); + Console.WriteLine("0. Выход"); + + string choice = Console.ReadLine(); + + switch (choice) + { + case "1": + _userConsoleUI.DisplayAllUsers(); + break; + case "2": + RemoveUser(); + break; + case "0": + return; + default: + Console.WriteLine("Неверный выбор, попробуйте снова."); + break; + } + + Console.WriteLine("Нажмите любую клавишу для продолжения..."); + Console.ReadKey(); + } + } + + private void RemoveUser() + { + Console.Write("Введите GUID пользователя для удаления: "); + string input = Console.ReadLine(); + + if (Guid.TryParse(input, out Guid userGuid)) + { + _userConsoleUI.RemoveUserByGuid(userGuid); + } + else + { + Console.WriteLine("Неверный формат GUID. Пожалуйста, попробуйте еще раз."); + } + } + } +} \ No newline at end of file diff --git a/Demo/UI/PresenceConsole.cs b/Demo/UI/PresenceConsole.cs new file mode 100644 index 0000000..0820bae --- /dev/null +++ b/Demo/UI/PresenceConsole.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.UI +{ + public class PresenceConsole + { + } +} \ No newline at end of file diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs new file mode 100644 index 0000000..ac1e979 --- /dev/null +++ b/Demo/UI/UserConsole.cs @@ -0,0 +1,53 @@ +using Demo.domain.Models; +using Demo.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo.UI +{ + + public class UserConsoleUI + { + UserUseCase _userUseCase; + public UserConsoleUI(UserUseCase userUseCase) + { + _userUseCase = userUseCase; + } + + public void RemoveUserByGuid(Guid guidUser) + { + + string del = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; + Console.WriteLine(del); + } + + public void DisplayAllUsers() + { + StringBuilder userOutput = new StringBuilder(); + foreach (var user in _userUseCase.GetAllUsers()) + { + userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}"); + } + Console.WriteLine(userOutput); + } + + public void UpdateUserGuid(Guid guidUser) + { + var user = _userUseCase.FindUserByGuid(guidUser); + Console.WriteLine($"Текущие данные: {user.FIO}, {user.Group.Name}"); + Console.Write("Введите новое ФИО: "); + string newFIO = Console.ReadLine(); + user.FIO = newFIO; + _userUseCase.UpdateUser(user); + } + + public void GetUserByGuid(Guid guidUser) + { + var user = _userUseCase.FindUserByGuid(guidUser); + Console.WriteLine($"Пользователь найден: {user.Guid}, {user.FIO}, {user.Group.Name}"); + } + } +} \ No newline at end of file