commit 71b5a3c2837384ab3b6285a4c3d50906eb3b91cd Author: adm Date: Mon Oct 21 15:41:56 2024 +0300 init 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/Exceptions/GroupNotFoundException.cs b/Demo/Data/Exceptions/GroupNotFoundException.cs new file mode 100644 index 0000000..de2876b --- /dev/null +++ b/Demo/Data/Exceptions/GroupNotFoundException.cs @@ -0,0 +1,10 @@ +using System; + +namespace Demo.Data.Exceptions +{ + public class GroupNotFoundException : RepositoryException + { + public GroupNotFoundException(int userId) + : base($"Группа с ID {userId} не найдена.") { } + } +} \ No newline at end of file diff --git a/Demo/Data/Exceptions/RepositoryException.cs b/Demo/Data/Exceptions/RepositoryException.cs new file mode 100644 index 0000000..5732bc4 --- /dev/null +++ b/Demo/Data/Exceptions/RepositoryException.cs @@ -0,0 +1,9 @@ +using System; + +namespace Demo.Data.Exceptions +{ + public class RepositoryException : Exception + { + public RepositoryException(string message) : base(message) { } + } +} \ No newline at end of file diff --git a/Demo/Data/Exceptions/UserNotFoundException.cs b/Demo/Data/Exceptions/UserNotFoundException.cs new file mode 100644 index 0000000..c05fdea --- /dev/null +++ b/Demo/Data/Exceptions/UserNotFoundException.cs @@ -0,0 +1,10 @@ +using System; + +namespace Demo.Data.Exceptions +{ + public class UserNotFoundException : RepositoryException + { + public UserNotFoundException(int userId) + : base($"Пользователь с ID {userId} не найден.") { } + } +} \ No newline at end of file diff --git a/Demo/Data/LocalData/Entity/Group.cs b/Demo/Data/LocalData/Entity/Group.cs new file mode 100644 index 0000000..6041311 --- /dev/null +++ b/Demo/Data/LocalData/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/LocalData/Entity/Presence.cs b/Demo/Data/LocalData/Entity/Presence.cs new file mode 100644 index 0000000..70b8d1e --- /dev/null +++ b/Demo/Data/LocalData/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/LocalData/Entity/User.cs b/Demo/Data/LocalData/Entity/User.cs new file mode 100644 index 0000000..ced6dd6 --- /dev/null +++ b/Demo/Data/LocalData/Entity/User.cs @@ -0,0 +1,26 @@ +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 int ID { 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..6783206 --- /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{ID = 1,Guid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "RandomFio", GroupID = 1 }, + new UserLocalEnity{ID = 2,Guid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "RandomFio1", GroupID = 2 }, + new UserLocalEnity{ID = 3, Guid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "RandomFio2", GroupID = 3 }, + new UserLocalEnity{ID = 4, Guid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "RandomFio3", GroupID = 1 }, + new UserLocalEnity{ID = 5, Guid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "RandomFio4", GroupID = 2 }, + new UserLocalEnity{ID = 6, 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..7557ff8 --- /dev/null +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -0,0 +1,53 @@ +using Demo.Data.Exceptions; +using Demo.Data.LocalData; +using Demo.domain.Models; +using System.Collections.Generic; +using System.Linq; + +public class GroupRepositoryImpl +{ + private List _groups = LocalStaticData.groups; + + + public GroupLocalEntity? GetGroupById(int groupId) + { + foreach (var group in _groups) + { + if (group.Id == groupId) + { + return group; + } + } + return null; + } + + + + + // Метод для получения всех групп + 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 UpdateGroup(GroupLocalEntity group) + { + var existingGroup = GetGroupById(group.Id); + if (existingGroup == null) throw new GroupNotFoundException(group.Id); + } + + public void RemoveGroupById(GroupLocalEntity group) + { + var existingGroup = GetGroupById(group.Id); + if (existingGroup == null) throw new GroupNotFoundException(group.Id); + if (_groups.Contains(existingGroup)) + { + _groups.Remove(existingGroup); + } + } +} diff --git a/Demo/Data/Repository/IGroupRepository.cs b/Demo/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..4abaa92 --- /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); + } +} \ No newline at end of file diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs new file mode 100644 index 0000000..86dcb88 --- /dev/null +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -0,0 +1,41 @@ +using Demo.Data.Exceptions; +using Demo.Data.LocalData; +using Demo.domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Demo.Data.Repository +{ + public class UserRepositoryImpl + { + private List _users; + + public UserRepositoryImpl() + { + _users = LocalStaticData.users; + } + + public IEnumerable GetAllUsers => _users; + + public bool RemoveUserById(int userId) + { + var user = _users.FirstOrDefault(u => u.ID == userId); + if (user == null) throw new UserNotFoundException(userId); + + _users.Remove(user); + return true; + } + + public UserLocalEnity? UpdateUser(UserLocalEnity user) + { + var existingUser = _users.FirstOrDefault(u => u.Guid == user.Guid); + if (existingUser == null) throw new UserNotFoundException(user.ID); + + existingUser.FIO = user.FIO; + existingUser.GroupID = user.GroupID; + + return existingUser; + } + } +} diff --git a/Demo/Demo.csproj b/Demo/Demo.csproj new file mode 100644 index 0000000..1ea2759 --- /dev/null +++ b/Demo/Demo.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + 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..0035a5b --- /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 int ID { get; set; } + public required Group Group { get; set; } + } +} diff --git a/Demo/Domain/UseCase/GroupUseCase.cs b/Demo/Domain/UseCase/GroupUseCase.cs new file mode 100644 index 0000000..1b39ef0 --- /dev/null +++ b/Demo/Domain/UseCase/GroupUseCase.cs @@ -0,0 +1,123 @@ +using Demo.Data.LocalData; +using Demo.domain.Models; + +namespace Demo.Domain.UseCase +{ + public class GroupUseCase + { + private readonly GroupRepositoryImpl _repositoryGroupImpl; + + public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl) + { + _repositoryGroupImpl = repositoryGroupImpl; + } + + // Приватный метод для валидации имени группы + private void ValidateGroupName(string groupName) + { + if (string.IsNullOrWhiteSpace(groupName)) + { + throw new ArgumentException("Имя группы не может быть пустым."); + } + } + + private void ValidateGroupId(int GroupId) + { + if(GroupId < 1) + { + throw new ArgumentException("Введите корректный ID группы."); + } + } + + // Приватный метод для валидации существования группы по ID + private GroupLocalEntity ValidateGroupExistence(int groupId) + { + var existingGroup = _repositoryGroupImpl.GetAllGroups() + .FirstOrDefault(g => g.Id == groupId); + + if (existingGroup == null) + { + throw new ArgumentException("Группа не найдена."); + } + + return existingGroup; + } + + + // Метод для получения списка всех групп + public List GetAllGroups() + { + return _repositoryGroupImpl.GetAllGroups() + .Select(it => new Group { Id = it.Id, Name = it.Name }) + .ToList(); + } + + + public void FindGroupById(int IdGroup) + { + List GetAllGroups() + { + return _repositoryGroupImpl.GetAllGroups() + .Select(it => new Group { Id = it.Id, Name = it.Name }) + .ToList(); + } + foreach(var group in GetAllGroups()) + { + if (IdGroup == group.Id) + { + Console.WriteLine($"ID группы: {group.Id} Название группы: {group.Name}"); + } + } + } + + + // Метод для добавления новой группы + public void AddGroup(string groupName) + { + ValidateGroupName(groupName); + + var newId = _repositoryGroupImpl.GetAllGroups().Any() + ? _repositoryGroupImpl.GetAllGroups().Max(g => g.Id) + 1 + : 1; + + GroupLocalEntity newGroup = new GroupLocalEntity + { + Id = newId, + Name = groupName + }; + + _repositoryGroupImpl.AddGroup(newGroup); + } + + public void RemoveGroupById(int groupId) + { + ValidateGroupId(groupId); + var existingGroup = ValidateGroupExistence(groupId); + List _groups = GetAllGroups(); + + // Находим группу по ID и удаляем ее + var groupToRemove = _groups.FirstOrDefault(g => g.Id == existingGroup.Id); + if (groupToRemove != null) + { + _groups.Remove(groupToRemove); + _repositoryGroupImpl.RemoveGroupById(existingGroup); + } + else + { + throw new ArgumentException("Группа не найдена."); + // Обработка случая, если группа не найдена (например, выброс исключения) + } + } + + + // Метод для изменения названия группы + public void UpdateGroup(int groupId, string newGroupName) + { + ValidateGroupName(newGroupName); + var existingGroup = ValidateGroupExistence(groupId); + + existingGroup.Name = newGroupName; + _repositoryGroupImpl.UpdateGroup(existingGroup); + } + } +} \ 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..600c2ec --- /dev/null +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -0,0 +1,136 @@ +using Demo.Data.Exceptions; +using Demo.Data.Repository; +using Demo.domain.Models; + +namespace Demo.Domain.UseCase +{ + public class UserUseCase + { + private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly GroupRepositoryImpl _repositoryGroupImpl; + + public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) + { + _repositoryUserImpl = repositoryImpl; + _repositoryGroupImpl = repositoryGroupImpl; + } + + // Приватный метод для валидации ФИО пользователя + private void ValidateUserFIO(string fio) + { + if (string.IsNullOrWhiteSpace(fio)) + { + throw new ArgumentException("ФИО не может быть пустым."); + } + } + + // Приватный метод для валидации существования пользователя по ID + private UserLocalEnity ValidateUserExistence(int userId) + { + var user = _repositoryUserImpl.GetAllUsers + .FirstOrDefault(u => u.ID == userId); + + if (user == null) + { + throw new Exception("Пользователь не найден."); + } + + return user; + } + + // Приватный метод для валидации существования группы по ID + private GroupLocalEntity ValidateGroupExistence(int groupId) + { + var group = _repositoryGroupImpl.GetAllGroups() + .FirstOrDefault(g => g.Id == groupId); + + if (group == null) + { + throw new Exception("Группа не найдена."); + } + + return group; + } + + // Вывести всех пользователей + public List GetAllUsers() => _repositoryUserImpl.GetAllUsers + .Join(_repositoryGroupImpl.GetAllGroups(), + user => user.GroupID, + group => group.Id, + (user, group) => + new User + { + ID = user.ID, + FIO = user.FIO, + Guid = user.Guid, + Group = new Group { Id = group.Id, Name = group.Name } + }).ToList(); + + // Удалить пользователя по id + public bool RemoveUserById(int userId) + { + try + { + return _repositoryUserImpl.RemoveUserById(userId); + } + catch (UserNotFoundException ex) + { + Console.WriteLine($"Ошибка: {ex.Message}"); + return false; + } + catch (RepositoryException ex) + { + Console.WriteLine($"Ошибка в репозитории: {ex.Message}"); + return false; + } + } + + // Обновить пользователя по guid + public User UpdateUser(User user) + { + ValidateUserFIO(user.FIO); + ValidateGroupExistence(user.Group.Id); + + 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("Ошибка при обновлении пользователя."); + } + + var groupEntity = ValidateGroupExistence(result.GroupID); + + return new User + { + FIO = result.FIO, + Guid = result.Guid, + Group = new Group + { + Id = groupEntity.Id, + Name = groupEntity.Name + } + }; + } + + // Найти пользователя по id + public User FindUserById(int userId) + { + var user = ValidateUserExistence(userId); + var group = ValidateGroupExistence(user.GroupID); + + return new User + { + FIO = user.FIO, + Guid = user.Guid, + Group = new Group { Id = group.Id, Name = group.Name } + }; + } + } +} diff --git a/Demo/Program.cs b/Demo/Program.cs new file mode 100644 index 0000000..889ba75 --- /dev/null +++ b/Demo/Program.cs @@ -0,0 +1,15 @@ +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); + +GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); + +MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); + +mainMenuUI.DisplayMenu(); diff --git a/Demo/UI/GroupConsole.cs b/Demo/UI/GroupConsole.cs new file mode 100644 index 0000000..dab1660 --- /dev/null +++ b/Demo/UI/GroupConsole.cs @@ -0,0 +1,64 @@ +using Demo.Domain.UseCase; +using System; +using System.Text; + +namespace Demo.UI +{ + public class GroupConsoleUI + { + private readonly GroupUseCase _groupUseCase; + + public GroupConsoleUI(GroupUseCase groupUseCase) + { + _groupUseCase = groupUseCase; + } + + public void FindGroupById(int IdGroup) + { + _groupUseCase.FindGroupById(IdGroup); + } + + // Метод для отображения всех групп + public void DisplayAllGroups() + { + Console.WriteLine("\n=== Список всех групп ==="); + StringBuilder groupOutput = new StringBuilder(); + + foreach (var group in _groupUseCase.GetAllGroups()) + { + groupOutput.AppendLine($"{group.Id}\t{group.Name}"); + } + + Console.WriteLine(groupOutput); + Console.WriteLine("===========================\n"); + } + + // Метод для добавления новой группы + public void AddGroup(string groupName) + { + try + { + _groupUseCase.AddGroup(groupName); + Console.WriteLine($"\nГруппа {groupName} добавлена.\n"); + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка: {ex.Message}\n"); + } + } + + public void RemoveGroup(string groupIdStr) + { + int groupId = int.Parse(groupIdStr); + _groupUseCase.RemoveGroupById(groupId); + Console.WriteLine($"Группа с ID: {groupId} удалена"); + } + + // Метод для обновления названия группы + public void UpdateGroupName(int groupId, string newGroupName) + { + _groupUseCase.UpdateGroup(groupId, newGroupName); + Console.WriteLine($"\nНазвание группы с ID {groupId} изменено на {newGroupName}.\n"); + } + } +} diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs new file mode 100644 index 0000000..fa7e1ee --- /dev/null +++ b/Demo/UI/MainMenu.cs @@ -0,0 +1,147 @@ +using Demo.Domain.UseCase; +using System; + +namespace Demo.UI +{ + public class MainMenuUI + { + private readonly UserConsoleUI _userConsoleUI; + private readonly GroupConsoleUI _groupConsoleUI; + + public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase) + { + _userConsoleUI = new UserConsoleUI(userUseCase); + _groupConsoleUI = new GroupConsoleUI(groupUseCase); + } + + public void DisplayMenu() + { + while (true) + { + Console.WriteLine("\n=-= Главное меню =-=\n"); + + Console.WriteLine("=-= Команды с Пользователями =-="); + Console.WriteLine("1. Вывести всех пользователей"); + Console.WriteLine("2. Удалить пользователя по id"); + Console.WriteLine("3. Обновить пользователя по id"); + Console.WriteLine("4. Найти пользователя по id"); + Console.WriteLine(); + + Console.WriteLine("=-= Команды с Группами =-="); + Console.WriteLine("5. Вывести все группы"); + Console.WriteLine("6. Добавить группу"); + Console.WriteLine("7. Удалить группу"); + Console.WriteLine("8. Изменить название группы"); + Console.WriteLine("9. Поиск группы по ID"); + Console.WriteLine(); + Console.WriteLine("0. Выход"); + Console.WriteLine(); + + Console.Write("\nВаш выбор: "); + string comand = Console.ReadLine(); + Console.WriteLine(); + + switch (comand) + { + case "1": + // Отображение всех пользователей + _userConsoleUI.DisplayAllUsers(); + break; + + case "2": + // Удаление пользователя по ID + Console.Write("Введите ID пользователя для удаления: "); + string inputId = Console.ReadLine(); + if (int.TryParse(inputId, out int userId)) + { + _userConsoleUI.RemoveUserById(userId); + } + else + { + Console.WriteLine("Неверный формат ID"); + } + break; + + case "3": + // Обновление пользователя по ID + Console.Write("Введите ID пользователя для обновления: "); + string updateIdInput = Console.ReadLine(); + if (int.TryParse(updateIdInput, out int updateUserId)) + { + _userConsoleUI.UpdateUserById(updateUserId); + } + else + { + Console.WriteLine("Неверный формат ID"); + } + break; + + case "4": + // Поиск пользователя по ID + Console.Write("Введите ID пользователя для поиска: "); + string findIdInput = Console.ReadLine(); + if (int.TryParse(findIdInput, out int findUserId)) + { + _userConsoleUI.FindUserById(findUserId); + } + else + { + Console.WriteLine("Неверный формат ID"); + } + break; + + case "5": + // Отображение всех групп + _groupConsoleUI.DisplayAllGroups(); + break; + + case "6": + // Добавление новой группы + Console.Write("Введите название новой группы: "); + string newGroupName = Console.ReadLine(); + _groupConsoleUI.AddGroup(newGroupName); + break; + + case "7": + // Удаление группы + Console.Write("Введите ID группы для удаления: "); + string groupIdForDelete=Console.ReadLine(); + _groupConsoleUI.RemoveGroup(groupIdForDelete); + break; + + case "8": + // Изменение названия группы + Console.Write("Введите ID группы для изменения: "); + if (int.TryParse(Console.ReadLine(), out int groupId)) + { + Console.Write("Введите новое название группы: "); + string newName = Console.ReadLine(); + _groupConsoleUI.UpdateGroupName(groupId, newName); + } + else + { + Console.WriteLine("Неверный формат ID группы"); + } + break; + + case "9": + // Поиск группы + Console.Write("Введите ID группы для поиска : "); + if(int.TryParse(Console.ReadLine(), out int IdGroup)){ + _groupConsoleUI.FindGroupById(IdGroup); + } + break; + + case "0": + Console.WriteLine("Выход..."); + return; + + default: + Console.WriteLine("Неверный выбор, попробуйте снова."); + break; + } + Console.WriteLine(); + } + } + } +} diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs new file mode 100644 index 0000000..48d9a71 --- /dev/null +++ b/Demo/UI/UserConsole.cs @@ -0,0 +1,74 @@ +using Demo.Domain.UseCase; +using System; +using System.Text; + +namespace Demo.UI +{ + public class UserConsoleUI + { + private readonly UserUseCase _userUseCase; + + public UserConsoleUI(UserUseCase userUseCase) + { + _userUseCase = userUseCase; + } + + // Метод для отображения всех пользователей + public void DisplayAllUsers() + { + Console.WriteLine("\n=== Список всех пользователей ==="); + StringBuilder userOutput = new StringBuilder(); + + foreach (var user in _userUseCase.GetAllUsers()) + { + userOutput.AppendLine($"{user.ID}\t{user.Guid}\t{user.FIO}\t{user.Group.Name}"); + } + + Console.WriteLine(userOutput); + Console.WriteLine("===============================\n"); + } + + // Метод для удаления пользователя по ID + public void RemoveUserById(int userId) + { + string output = _userUseCase.RemoveUserById(userId) ? "Пользователь удален" : "Пользователь не найден"; + Console.WriteLine($"\n{output}\n"); + } + + // Метод для обновления пользователя по ID + public void UpdateUserById(int userId) + { + try + { + var user = _userUseCase.FindUserById(userId); + + Console.WriteLine($"Текущие данные: {user.FIO}, {user.Group.Name}"); + Console.Write("\nВведите новое ФИО: "); + string newFIO = Console.ReadLine(); + + user.FIO = newFIO; + _userUseCase.UpdateUser(user); + + Console.WriteLine("\nПользователь обновлен.\n"); + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка: {ex.Message}\n"); + } + } + + // Метод для поиска пользователя по ID + public void FindUserById(int userId) + { + var user = _userUseCase.FindUserById(userId); + if (user != null) + { + Console.WriteLine($"\nПользователь найден: {user.Guid}, {user.FIO}, {user.Group.Name}\n"); + } + else + { + Console.WriteLine("\nПользователь не найден.\n"); + } + } + } +} diff --git a/Demo/bin/Debug/net8.0/Demo.deps.json b/Demo/bin/Debug/net8.0/Demo.deps.json new file mode 100644 index 0000000..34d15c4 --- /dev/null +++ b/Demo/bin/Debug/net8.0/Demo.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v8.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v8.0": { + "Demo/1.0.0": { + "runtime": { + "Demo.dll": {} + } + } + } + }, + "libraries": { + "Demo/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/Demo/bin/Debug/net8.0/Demo.dll b/Demo/bin/Debug/net8.0/Demo.dll new file mode 100644 index 0000000..405e53d Binary files /dev/null and b/Demo/bin/Debug/net8.0/Demo.dll differ diff --git a/Demo/bin/Debug/net8.0/Demo.exe b/Demo/bin/Debug/net8.0/Demo.exe new file mode 100644 index 0000000..642b6dd Binary files /dev/null and b/Demo/bin/Debug/net8.0/Demo.exe differ diff --git a/Demo/bin/Debug/net8.0/Demo.pdb b/Demo/bin/Debug/net8.0/Demo.pdb new file mode 100644 index 0000000..fe832ab Binary files /dev/null and b/Demo/bin/Debug/net8.0/Demo.pdb differ diff --git a/Demo/bin/Debug/net8.0/Demo.runtimeconfig.json b/Demo/bin/Debug/net8.0/Demo.runtimeconfig.json new file mode 100644 index 0000000..becfaea --- /dev/null +++ b/Demo/bin/Debug/net8.0/Demo.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net8.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "8.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/Demo/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs b/Demo/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs new file mode 100644 index 0000000..2217181 --- /dev/null +++ b/Demo/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] diff --git a/Demo/obj/Debug/net8.0/Demo.AssemblyInfo.cs b/Demo/obj/Debug/net8.0/Demo.AssemblyInfo.cs new file mode 100644 index 0000000..34b81cf --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.AssemblyInfo.cs @@ -0,0 +1,23 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("Demo")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6be91a3daa12e11afafcb7bfa8a381851a1c6d13")] +[assembly: System.Reflection.AssemblyProductAttribute("Demo")] +[assembly: System.Reflection.AssemblyTitleAttribute("Demo")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Создано классом WriteCodeFragment MSBuild. + diff --git a/Demo/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache b/Demo/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache new file mode 100644 index 0000000..648fa0d --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +597fa958725b79051cce88e5b66d8ff3029ce88e040c90e31a5a5829fb266be4 diff --git a/Demo/obj/Debug/net8.0/Demo.GeneratedMSBuildEditorConfig.editorconfig b/Demo/obj/Debug/net8.0/Demo.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..04e5033 --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,13 @@ +is_global = true +build_property.TargetFramework = net8.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = Demo +build_property.ProjectDir = C:\Users\adm\source\repos\presence_new\Demo\ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = diff --git a/Demo/obj/Debug/net8.0/Demo.GlobalUsings.g.cs b/Demo/obj/Debug/net8.0/Demo.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/Demo/obj/Debug/net8.0/Demo.assets.cache b/Demo/obj/Debug/net8.0/Demo.assets.cache new file mode 100644 index 0000000..15ee166 Binary files /dev/null and b/Demo/obj/Debug/net8.0/Demo.assets.cache differ diff --git a/Demo/obj/Debug/net8.0/Demo.csproj.BuildWithSkipAnalyzers b/Demo/obj/Debug/net8.0/Demo.csproj.BuildWithSkipAnalyzers new file mode 100644 index 0000000..e69de29 diff --git a/Demo/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache b/Demo/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..015a07c --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +ed5a8c36a17dc0ce1f0584a54124cf9ca5fb6a4c72ce3bba4b5a671138ebee45 diff --git a/Demo/obj/Debug/net8.0/Demo.csproj.FileListAbsolute.txt b/Demo/obj/Debug/net8.0/Demo.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..62bc8d7 --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.csproj.FileListAbsolute.txt @@ -0,0 +1,14 @@ +C:\Users\adm\Source\Repos\presence_new\Demo\bin\Debug\net8.0\Demo.exe +C:\Users\adm\Source\Repos\presence_new\Demo\bin\Debug\net8.0\Demo.deps.json +C:\Users\adm\Source\Repos\presence_new\Demo\bin\Debug\net8.0\Demo.runtimeconfig.json +C:\Users\adm\Source\Repos\presence_new\Demo\bin\Debug\net8.0\Demo.dll +C:\Users\adm\Source\Repos\presence_new\Demo\bin\Debug\net8.0\Demo.pdb +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.GeneratedMSBuildEditorConfig.editorconfig +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.AssemblyInfoInputs.cache +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.AssemblyInfo.cs +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.csproj.CoreCompileInputs.cache +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.dll +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\refint\Demo.dll +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.pdb +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\Demo.genruntimeconfig.cache +C:\Users\adm\Source\Repos\presence_new\Demo\obj\Debug\net8.0\ref\Demo.dll diff --git a/Demo/obj/Debug/net8.0/Demo.dll b/Demo/obj/Debug/net8.0/Demo.dll new file mode 100644 index 0000000..405e53d Binary files /dev/null and b/Demo/obj/Debug/net8.0/Demo.dll differ diff --git a/Demo/obj/Debug/net8.0/Demo.genruntimeconfig.cache b/Demo/obj/Debug/net8.0/Demo.genruntimeconfig.cache new file mode 100644 index 0000000..ddc833d --- /dev/null +++ b/Demo/obj/Debug/net8.0/Demo.genruntimeconfig.cache @@ -0,0 +1 @@ +9b1e2cf713fac6b5af6fdc748e02588a118e0108e8af9c39763b31b5c1f122c1 diff --git a/Demo/obj/Debug/net8.0/Demo.pdb b/Demo/obj/Debug/net8.0/Demo.pdb new file mode 100644 index 0000000..fe832ab Binary files /dev/null and b/Demo/obj/Debug/net8.0/Demo.pdb differ diff --git a/Demo/obj/Debug/net8.0/apphost.exe b/Demo/obj/Debug/net8.0/apphost.exe new file mode 100644 index 0000000..642b6dd Binary files /dev/null and b/Demo/obj/Debug/net8.0/apphost.exe differ diff --git a/Demo/obj/Debug/net8.0/ref/Demo.dll b/Demo/obj/Debug/net8.0/ref/Demo.dll new file mode 100644 index 0000000..8208914 Binary files /dev/null and b/Demo/obj/Debug/net8.0/ref/Demo.dll differ diff --git a/Demo/obj/Debug/net8.0/refint/Demo.dll b/Demo/obj/Debug/net8.0/refint/Demo.dll new file mode 100644 index 0000000..8208914 Binary files /dev/null and b/Demo/obj/Debug/net8.0/refint/Demo.dll differ diff --git a/Demo/obj/Demo.csproj.nuget.dgspec.json b/Demo/obj/Demo.csproj.nuget.dgspec.json new file mode 100644 index 0000000..2564ebb --- /dev/null +++ b/Demo/obj/Demo.csproj.nuget.dgspec.json @@ -0,0 +1,68 @@ +{ + "format": 1, + "restore": { + "C:\\Users\\adm\\source\\repos\\presence_new\\Demo\\Demo.csproj": {} + }, + "projects": { + "C:\\Users\\adm\\source\\repos\\presence_new\\Demo\\Demo.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\adm\\source\\repos\\presence_new\\Demo\\Demo.csproj", + "projectName": "Demo", + "projectPath": "C:\\Users\\adm\\source\\repos\\presence_new\\Demo\\Demo.csproj", + "packagesPath": "C:\\Users\\adm\\.nuget\\packages\\", + "outputPath": "C:\\Users\\adm\\Source\\Repos\\presence_new\\Demo\\obj\\", + "projectStyle": "PackageReference", + "configFilePaths": [ + "C:\\Users\\adm\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/Demo/obj/Demo.csproj.nuget.g.props b/Demo/obj/Demo.csproj.nuget.g.props new file mode 100644 index 0000000..b002ca2 --- /dev/null +++ b/Demo/obj/Demo.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + $(UserProfile)\.nuget\packages\ + C:\Users\adm\.nuget\packages\ + PackageReference + 6.11.0 + + + + + \ No newline at end of file diff --git a/Demo/obj/Demo.csproj.nuget.g.targets b/Demo/obj/Demo.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/Demo/obj/Demo.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Demo/obj/project.assets.json b/Demo/obj/project.assets.json new file mode 100644 index 0000000..531e787 --- /dev/null +++ b/Demo/obj/project.assets.json @@ -0,0 +1,73 @@ +{ + "version": 3, + "targets": { + "net8.0": {} + }, + "libraries": {}, + "projectFileDependencyGroups": { + "net8.0": [] + }, + "packageFolders": { + "C:\\Users\\adm\\.nuget\\packages\\": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\adm\\Source\\Repos\\presence_new\\Demo\\Demo.csproj", + "projectName": "Demo", + "projectPath": "C:\\Users\\adm\\Source\\Repos\\presence_new\\Demo\\Demo.csproj", + "packagesPath": "C:\\Users\\adm\\.nuget\\packages\\", + "outputPath": "C:\\Users\\adm\\Source\\Repos\\presence_new\\Demo\\obj\\", + "projectStyle": "PackageReference", + "configFilePaths": [ + "C:\\Users\\adm\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net8.0" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + }, + "restoreAuditProperties": { + "enableAudit": "true", + "auditLevel": "low", + "auditMode": "direct" + } + }, + "frameworks": { + "net8.0": { + "targetAlias": "net8.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/Demo/obj/project.nuget.cache b/Demo/obj/project.nuget.cache new file mode 100644 index 0000000..a18cb1c --- /dev/null +++ b/Demo/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "+PcSJ/mMOPQ=", + "success": true, + "projectFilePath": "C:\\Users\\adm\\source\\repos\\presence_new\\Demo\\Demo.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file