diff --git a/123.sln b/123.sln new file mode 100644 index 0000000..b6a511f --- /dev/null +++ b/123.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", "123\Demo.csproj", "{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B3D7FA9B-E7AA-4A2B-8D13-416D51577CB6} + EndGlobalSection +EndGlobal diff --git a/123.zip b/123.zip new file mode 100644 index 0000000..dfdcb7c Binary files /dev/null and b/123.zip differ diff --git a/123/Data/LocalData/Entity/Group.cs b/123/Data/LocalData/Entity/Group.cs new file mode 100644 index 0000000..85f909c --- /dev/null +++ b/123/Data/LocalData/Entity/Group.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.LocalData.Entity +{ + public class GroupLocalEntity + { + public int ID { get; set; } + public required string Name { get; set; } + } +} diff --git a/123/Data/LocalData/Entity/Presence.cs b/123/Data/LocalData/Entity/Presence.cs new file mode 100644 index 0000000..dde230d --- /dev/null +++ b/123/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 _123.Data.LocalData.Entity +{ + public 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/123/Data/LocalData/Entity/User.cs b/123/Data/LocalData/Entity/User.cs new file mode 100644 index 0000000..f6284e7 --- /dev/null +++ b/123/Data/LocalData/Entity/User.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.LocalData.Entity +{ + public class UserLocalEntity : IEquatable + { + public required string UserFIO { get; set; } + public Guid UserGuid { get; set; } + + public required int GroupID { get; set; } + public bool Equals(UserLocalEntity? other) + { + if (other == null) return false; + return this.UserGuid.Equals(other.UserGuid); + } + } +} diff --git a/123/Data/LocalData/LocalStaticData.cs b/123/Data/LocalData/LocalStaticData.cs new file mode 100644 index 0000000..f65a867 --- /dev/null +++ b/123/Data/LocalData/LocalStaticData.cs @@ -0,0 +1,32 @@ +using _123.Data.LocalData.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.LocalData +{ + public 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 UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio", GroupID = 1 }, + new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio1", GroupID = 2 }, + new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio2", GroupID = 3 }, + new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio3", GroupID = 1 }, + new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio4", GroupID = 2 }, + new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio5", GroupID = 3 }, + }; + public static List presences => new List + { + + }; + } +} diff --git a/123/Data/ReportsHistory/GroupRepositoty.cs b/123/Data/ReportsHistory/GroupRepositoty.cs new file mode 100644 index 0000000..a84260b --- /dev/null +++ b/123/Data/ReportsHistory/GroupRepositoty.cs @@ -0,0 +1,26 @@ +using _123.Data.LocalData.Entity; +using _123.Data.LocalData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Data.ReportsHistory +{ + + public class GroupRepositoryImpl + { + public List GetAllGroups() => LocalStaticData.groups; + + public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.ID == groupUpdateLocalEntity.ID).FirstOrDefault(); + if (groupLocal == null) return null; + groupLocal.ID = groupUpdateLocalEntity.ID; + groupLocal.Name = groupUpdateLocalEntity.Name; + return groupLocal; + } + } + } diff --git a/123/Data/ReportsHistory/UserRepositoty.cs b/123/Data/ReportsHistory/UserRepositoty.cs new file mode 100644 index 0000000..3bdc09b --- /dev/null +++ b/123/Data/ReportsHistory/UserRepositoty.cs @@ -0,0 +1,51 @@ +using _123.Data.LocalData; +using _123.Data.LocalData.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _123.Data.ReportsHistory +{ + public class UserRepositoryImpl + { + public UserRepositoryImpl() + { + + GetAllUsers = LocalStaticData.users; + } + public List GetAllUsers + { get; set; } + + public bool RemoveUserByGuid(Guid userGuid) + { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.UserGuid == userGuid).FirstOrDefault(); + if (userLocal == null) return false; + + return GetAllUsers.Remove(userLocal); + } + + public UserLocalEntity? GetUserByGuid(Guid userGuid) + { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.UserGuid == userGuid).FirstOrDefault(); + if (userLocal == null) return null; + + return userLocal; + } + + public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity) + { + UserLocalEntity? userLocal = GetAllUsers + .Where(x => x.UserGuid == userUpdateLocalEnity.UserGuid).FirstOrDefault(); + if (userLocal == null) return null; + userLocal.UserFIO = userUpdateLocalEnity.UserFIO; + userLocal.GroupID = userUpdateLocalEnity.GroupID; + return userLocal; + + } + } +} diff --git a/123/Demo.csproj b/123/Demo.csproj new file mode 100644 index 0000000..ebb8a92 --- /dev/null +++ b/123/Demo.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + _123 + enable + enable + + + + + + + diff --git a/123/Domain/Models/Group.cs b/123/Domain/Models/Group.cs new file mode 100644 index 0000000..0787c73 --- /dev/null +++ b/123/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 _123.Domain.Models +{ + public class Group + { + public int ID { get; set; } + public required string Name { get; set; } + } +} diff --git a/123/Domain/Models/Presence.cs b/123/Domain/Models/Presence.cs new file mode 100644 index 0000000..7d9746f --- /dev/null +++ b/123/Domain/Models/Presence.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.Domain.Models +{ + public class Presence + { + public DateOnly Date { get; set; } + public int ClassNum { get; set; } + public bool IsAttedance { get; set; } + public required User User { get; set; } + } +} diff --git a/123/Domain/Models/User.cs b/123/Domain/Models/User.cs new file mode 100644 index 0000000..e43f1e6 --- /dev/null +++ b/123/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 _123.Domain.Models +{ + public class User + { + public required string UserFIO { get; set; } + public Guid UserGuid { get; set; } + + public required Group UserGroup { get; set; } + } +} diff --git a/123/Domain/UseCase/GroupUseCase.cs b/123/Domain/UseCase/GroupUseCase.cs new file mode 100644 index 0000000..b877f3b --- /dev/null +++ b/123/Domain/UseCase/GroupUseCase.cs @@ -0,0 +1,33 @@ +using _123.Data.ReportsHistory; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using _123.Domain.Models; +using _123.Data.LocalData.Entity; + +namespace _123.Domain.UseCase +{ + public class GroupUseCase + { + private GroupRepositoryImpl _repositoryGroupImpl; + public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl) + { + _repositoryGroupImpl = repositoryGroupImpl; + } + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + .Select(it => new Group { ID = it.ID, Name = it.Name }).ToList(); + + public Group UpdateGroupName(Group grou) + { + GroupLocalEntity groupLocalEntity = new GroupLocalEntity { ID = grou.ID, Name = grou.Name }; + GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity); + if (result == null) throw new Exception(""); + Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.ID); + if (group == null) throw new Exception(""); + return new Group { ID = group.ID, Name = group.Name }; + } + } + +} diff --git a/123/Domain/UseCase/UserUseCase.cs b/123/Domain/UseCase/UserUseCase.cs new file mode 100644 index 0000000..212048b --- /dev/null +++ b/123/Domain/UseCase/UserUseCase.cs @@ -0,0 +1,53 @@ +using _123.Data.LocalData.Entity; +using _123.Data.ReportsHistory; +using _123.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.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 + { + UserFIO = user.UserFIO, + UserGuid = user.UserGuid, + UserGroup = new Group { ID = group.ID, Name = group.Name } + } + ).ToList(); + + public bool RemoveUserByGuid(Guid userGuid) + { + return _repositoryUserImpl.RemoveUserByGuid(userGuid); + } + public User UpdateUser(User user) + { + UserLocalEntity userLocalEnity = new UserLocalEntity { UserFIO = user.UserFIO, GroupID = user.UserGroup.ID, UserGuid = user.UserGuid }; + UserLocalEntity? 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 { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group }; + } + + } +} diff --git a/123/Program.cs b/123/Program.cs new file mode 100644 index 0000000..b9d7ee3 --- /dev/null +++ b/123/Program.cs @@ -0,0 +1,10 @@ +using _123.Data.ReportsHistory; +using _123.Domain.UseCase; +using _123.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); \ No newline at end of file diff --git a/123/UI/GroupConsole.cs b/123/UI/GroupConsole.cs new file mode 100644 index 0000000..2bb3fdb --- /dev/null +++ b/123/UI/GroupConsole.cs @@ -0,0 +1,26 @@ +using _123.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace _123.UI +{ + public class GroupConsoleUI + { + GroupUseCase _groupUseCase; + public GroupConsoleUI(GroupUseCase groupUseCase) + { + _groupUseCase = groupUseCase; + } + public void DisplayAllGroups() + { + StringBuilder groupOutput = new StringBuilder(); + foreach (var group in _groupUseCase.GetAllGroups()) + { + groupOutput.AppendLine($"{group.ID}\t{group.Name}"); + } + Console.WriteLine(groupOutput); + } + } +} \ No newline at end of file diff --git a/123/UI/MainMenu.cs b/123/UI/MainMenu.cs new file mode 100644 index 0000000..c06b921 --- /dev/null +++ b/123/UI/MainMenu.cs @@ -0,0 +1,45 @@ +using _123.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.UI +{ + public class MainMenuUI + { + + UserConsoleUI _userConsoleUI; + + GroupConsoleUI _groupConsoleUI; + + public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase) + { + _userConsoleUI = new UserConsoleUI(userUseCase); + _groupConsoleUI = new GroupConsoleUI(groupUseCase); + + DisplayMenu(); + + } + + private void DisplayMenu() + { + while (true) + { + switch (Console.ReadLine()) + { + case "1": _userConsoleUI.DisplayAllUsers(); break; + case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; + case "3": _groupConsoleUI.DisplayAllGroups(); break; + + default: + DisplayMenu(); + break; + } + + } + } + + } +} diff --git a/123/UI/UserConsole.cs b/123/UI/UserConsole.cs new file mode 100644 index 0000000..1007378 --- /dev/null +++ b/123/UI/UserConsole.cs @@ -0,0 +1,36 @@ +using _123.Domain.UseCase; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _123.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.UserGuid}\t{user.UserFIO}\t{user.UserGroup.Name}"); + } + Console.WriteLine(userOutput); + } + + } +}