commit abf6ba433d4ce49b4aeba240408d309cd171d16b Author: Nastya Date: Sun Oct 20 00:12:06 2024 +0300 first commit 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/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..5af4881 --- /dev/null +++ b/Demo/Data/LocalData/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..e5b9a29 --- /dev/null +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -0,0 +1,15 @@ +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 + { + public List GetAllGroups() => LocalStaticData.groups; + } +} 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/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..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/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs new file mode 100644 index 0000000..f1f44e1 --- /dev/null +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -0,0 +1,46 @@ +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}; + } + } +} diff --git a/Demo/Program.cs b/Demo/Program.cs new file mode 100644 index 0000000..9ebb621 --- /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); \ No newline at end of file diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs new file mode 100644 index 0000000..ce13884 --- /dev/null +++ b/Demo/UI/MainMenu.cs @@ -0,0 +1,37 @@ +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 + { + + UserConsoleUI _userConsoleUI; + + public MainMenuUI(UserUseCase userUseCase) { + _userConsoleUI = new UserConsoleUI(userUseCase); + DisplayMenu(); + + } + + private void DisplayMenu() { + while (true) + { + switch (Console.ReadLine()) + { + case "1": _userConsoleUI.DisplayAllUsers(); break; + case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; + + default: DisplayMenu(); + break; + } + + } + } + + } +} diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs new file mode 100644 index 0000000..15ec296 --- /dev/null +++ b/Demo/UI/UserConsole.cs @@ -0,0 +1,33 @@ +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 output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален"; + Console.WriteLine(output); + } + + 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); + } + } +}