diff --git a/Data/Repository/GroupRepositoryImpl.cs b/Data/Repository/GroupRepositoryImpl.cs index cd5ade0..420d951 100644 --- a/Data/Repository/GroupRepositoryImpl.cs +++ b/Data/Repository/GroupRepositoryImpl.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -10,24 +11,69 @@ using Posechaemost.Data.LocalData.Entity; namespace Posechaemost.Data.Repository { - public class GroupRepositoryImpl + public class GroupRepositoryImpl: IGroupRepository { - public List GetAllGroups() => LocalStaticData.groups; - public GroupLocalEntity? UpdateGroup(String name) + + public bool AddGroup(String name, String id) { - GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.Name == name).FirstOrDefault(); - if (groupLocal == null) return null; + GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + // GroupLocalEntity? group = new GroupLocalEntity(); groupLocal.Name = name; + groupLocal.Id = int.Parse(id); + return true; + } + + public List GetAllGroup() + { + throw new NotImplementedException(); + } + + public List GetAllGroups() => LocalStaticData.groups; + + public GroupLocalEntity GetGroupById(int groupID) + { + GroupLocalEntity groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return null; return groupLocal; } - public GroupLocalEntity? AddGroup(String name, String id) + public bool RemoveGroupById(int groupID) { - GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return false; + + return GetAllGroups().Remove(groupLocal); + } + + public bool UpdateGroupById(int groupID, String name) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return false; groupLocal.Name = name; - groupLocal.Id = int.Parse(id); - return groupLocal; + return true; } } -} \ No newline at end of file +} + // { + // public List GetAllGroups() => LocalStaticData.groups; + // public GroupLocalEntity? UpdateGroup(String name) + // { + // GroupLocalEntity? groupLocal = GetAllGroups() + // .Where(x => x.Name == name).FirstOrDefault(); + // if (groupLocal == null) return null; + // groupLocal.Name = name; + // return groupLocal; + // } + + // public GroupLocalEntity? AddGroup(String name, String id) + // { + // GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + // // GroupLocalEntity? group = new GroupLocalEntity(name, id); + // groupLocal.Name = name; + // groupLocal.Id = int.Parse(id); + // return groupLocal; + // } + // } \ No newline at end of file diff --git a/Data/Repository/IGroupRepository.cs b/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..a905320 --- /dev/null +++ b/Data/Repository/IGroupRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Posechaemost.Data.LocalData.Entity; + +namespace Posechaemost.Data.Repository { + public interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, String name); + GroupLocalEntity GetGroupById(int groupID); + bool AddGroup(String name, String id); + } +} \ No newline at end of file diff --git a/Data/Repository/IUserRepository.cs b/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..434d230 --- /dev/null +++ b/Data/Repository/IUserRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Posechaemost.Data.LocalData.Entity; + +namespace Posechaemost.Data.Repository { + public interface IUserRepository + { + List GetAllUser(); + bool RemoveUserByGuid(Guid userGuid); + UserLocalEntity? GetUserByGuid(Guid userGuid); + UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity); + UserLocalEntity? UpdateUserByGuid(Guid userGuid); + } +} \ No newline at end of file diff --git a/Data/Repository/UserRepositoryImpl.cs b/Data/Repository/UserRepositoryImpl.cs index bfd4af8..40ac56d 100644 --- a/Data/Repository/UserRepositoryImpl.cs +++ b/Data/Repository/UserRepositoryImpl.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Posechaemost.Data.LocalData; @@ -9,12 +8,18 @@ using Posechaemost.Data.LocalData.Entity; namespace Posechaemost.Data.Repository { - public class UserRepositoryImpl + public class UserRepositoryImpl: IUserRepository { public UserRepositoryImpl() { GetAllUsers = LocalStaticData.users; } + + public List GetAllUser() + { + throw new NotImplementedException(); + } + public List GetAllUsers { get; set; } diff --git a/Domain/UseCase/GroupUseCase.cs b/Domain/UseCase/GroupUseCase.cs index 8e1f375..b50305b 100644 --- a/Domain/UseCase/GroupUseCase.cs +++ b/Domain/UseCase/GroupUseCase.cs @@ -21,14 +21,10 @@ namespace Posechaemost.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public Group UpdateGroupName(String name, String name1) { - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result.Name); - if (group == null) throw new Exception(""); - return new Group {Id = group.Id, Name = name1}; + public bool UpdateGroupName(String id, String name1) { + return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1); } - public GroupLocalEntity AddGroup(String name, String id) + public bool AddGroup(String name, String id) { return _repositoryGroupImpl.AddGroup(name, id); } diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index e3cd964..e20a852 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -11,8 +11,9 @@ namespace Posechaemost.Domain.UseCase { public class UserUseCase { - private UserRepositoryImpl _repositoryUserImpl; - private GroupRepositoryImpl _repositoryGroupImpl; + + private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) { @@ -20,10 +21,10 @@ namespace Posechaemost.Domain.UseCase _repositoryGroupImpl = repositoryGroupImpl; } - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() + private List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); public List GetAllUsers() => _repositoryUserImpl.GetAllUsers - .Join(_repositoryGroupImpl.GetAllGroups(), + .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.Id, (user, group) => diff --git a/Posechaemost.csproj b/Posechaemost.csproj index 2150e37..434708c 100644 --- a/Posechaemost.csproj +++ b/Posechaemost.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/Program.cs b/Program.cs index 733ec2e..29074e5 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,19 @@ using Posechaemost.Data.Repository; using Posechaemost.Domain.UseCase; using Posechaemost.UI; +using Microsoft.Extensions.DependencyInjection; +using System.Text.RegularExpressions; + +IServiceCollection services = new ServiceCollection(); + +services + .AddSingleton() + .AddSingleton(); + +var serviceProvider = services.BuildServiceProvider(); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); -UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); -UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); +UserUseCase userUseCase = serviceProvider.GetService(); GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); \ No newline at end of file diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs index 0b70887..ebe20e9 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1305f40f241ce752d3c0a7ec5341b1eafac497d8")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+36a123355e04422229f0afaff5d2c6d503a8419e")] [assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache index a0f7286..7218ff6 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache @@ -1 +1 @@ -7a59f60438c72dd05578b09f953c9ba9d3343469014f076958deeba098123188 +c78a5718d92cc56f307f18b87610c16cd6bd4adb899ce2e54039bee5d3d6ceb2 diff --git a/obj/Debug/net8.0/Posechaemost.assets.cache b/obj/Debug/net8.0/Posechaemost.assets.cache index 94de1e1..b10d4ef 100644 Binary files a/obj/Debug/net8.0/Posechaemost.assets.cache and b/obj/Debug/net8.0/Posechaemost.assets.cache differ diff --git a/obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache b/obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache new file mode 100644 index 0000000..ecd6f6f Binary files /dev/null and b/obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache differ diff --git a/obj/Posechaemost.csproj.nuget.dgspec.json b/obj/Posechaemost.csproj.nuget.dgspec.json index 32a5d20..e82c204 100644 --- a/obj/Posechaemost.csproj.nuget.dgspec.json +++ b/obj/Posechaemost.csproj.nuget.dgspec.json @@ -42,6 +42,12 @@ "frameworks": { "net8.0": { "targetAlias": "net8.0", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": { + "target": "Package", + "version": "[8.0.1, )" + } + }, "imports": [ "net461", "net462", diff --git a/obj/project.assets.json b/obj/project.assets.json index 295b7a8..8e32f5e 100644 --- a/obj/project.assets.json +++ b/obj/project.assets.json @@ -1,11 +1,114 @@ { "version": 3, "targets": { - "net8.0": {} + "net8.0": { + "Microsoft.Extensions.DependencyInjection/8.0.1": { + "type": "package", + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.2" + }, + "compile": { + "lib/net8.0/Microsoft.Extensions.DependencyInjection.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net8.0/Microsoft.Extensions.DependencyInjection.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/net6.0/_._": {} + } + }, + "Microsoft.Extensions.DependencyInjection.Abstractions/8.0.2": { + "type": "package", + "compile": { + "lib/net8.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net8.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/net6.0/_._": {} + } + } + } + }, + "libraries": { + "Microsoft.Extensions.DependencyInjection/8.0.1": { + "sha512": "BmANAnR5Xd4Oqw7yQ75xOAYODybZQRzdeNucg7kS5wWKd2PNnMdYtJ2Vciy0QLylRmv42DGl5+AFL9izA6F1Rw==", + "type": "package", + "path": "microsoft.extensions.dependencyinjection/8.0.1", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "Icon.png", + "LICENSE.TXT", + "PACKAGE.md", + "THIRD-PARTY-NOTICES.TXT", + "buildTransitive/net461/Microsoft.Extensions.DependencyInjection.targets", + "buildTransitive/net462/_._", + "buildTransitive/net6.0/_._", + "buildTransitive/netcoreapp2.0/Microsoft.Extensions.DependencyInjection.targets", + "lib/net462/Microsoft.Extensions.DependencyInjection.dll", + "lib/net462/Microsoft.Extensions.DependencyInjection.xml", + "lib/net6.0/Microsoft.Extensions.DependencyInjection.dll", + "lib/net6.0/Microsoft.Extensions.DependencyInjection.xml", + "lib/net7.0/Microsoft.Extensions.DependencyInjection.dll", + "lib/net7.0/Microsoft.Extensions.DependencyInjection.xml", + "lib/net8.0/Microsoft.Extensions.DependencyInjection.dll", + "lib/net8.0/Microsoft.Extensions.DependencyInjection.xml", + "lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.dll", + "lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.xml", + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.dll", + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.xml", + "microsoft.extensions.dependencyinjection.8.0.1.nupkg.sha512", + "microsoft.extensions.dependencyinjection.nuspec", + "useSharedDesignerContext.txt" + ] + }, + "Microsoft.Extensions.DependencyInjection.Abstractions/8.0.2": { + "sha512": "3iE7UF7MQkCv1cxzCahz+Y/guQbTqieyxyaWKhrRO91itI9cOKO76OHeQDahqG4MmW5umr3CcCvGmK92lWNlbg==", + "type": "package", + "path": "microsoft.extensions.dependencyinjection.abstractions/8.0.2", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "Icon.png", + "LICENSE.TXT", + "PACKAGE.md", + "THIRD-PARTY-NOTICES.TXT", + "buildTransitive/net461/Microsoft.Extensions.DependencyInjection.Abstractions.targets", + "buildTransitive/net462/_._", + "buildTransitive/net6.0/_._", + "buildTransitive/netcoreapp2.0/Microsoft.Extensions.DependencyInjection.Abstractions.targets", + "lib/net462/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/net462/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "lib/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "lib/net7.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/net7.0/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "lib/net8.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/net8.0/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.Abstractions.dll", + "lib/netstandard2.1/Microsoft.Extensions.DependencyInjection.Abstractions.xml", + "microsoft.extensions.dependencyinjection.abstractions.8.0.2.nupkg.sha512", + "microsoft.extensions.dependencyinjection.abstractions.nuspec", + "useSharedDesignerContext.txt" + ] + } }, - "libraries": {}, "projectFileDependencyGroups": { - "net8.0": [] + "net8.0": [ + "Microsoft.Extensions.DependencyInjection >= 8.0.1" + ] }, "packageFolders": { "/home/gara/.nuget/packages/": {} @@ -48,6 +151,12 @@ "frameworks": { "net8.0": { "targetAlias": "net8.0", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": { + "target": "Package", + "version": "[8.0.1, )" + } + }, "imports": [ "net461", "net462", diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index cd49dd2..0bb2067 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,8 +1,11 @@ { "version": 2, - "dgSpecHash": "3K0+oSHYQvE=", + "dgSpecHash": "JxuWkwCqUKY=", "success": true, "projectFilePath": "/home/gara/csharp/Posechaemost/Posechaemost.csproj", - "expectedPackageFiles": [], + "expectedPackageFiles": [ + "/home/gara/.nuget/packages/microsoft.extensions.dependencyinjection/8.0.1/microsoft.extensions.dependencyinjection.8.0.1.nupkg.sha512", + "/home/gara/.nuget/packages/microsoft.extensions.dependencyinjection.abstractions/8.0.2/microsoft.extensions.dependencyinjection.abstractions.8.0.2.nupkg.sha512" + ], "logs": [] } \ No newline at end of file