a bunch of changes

This commit is contained in:
Dasha 2024-10-23 10:06:56 +03:00
parent 36a123355e
commit 8ea8d00df0
15 changed files with 247 additions and 34 deletions

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,24 +11,69 @@ using Posechaemost.Data.LocalData.Entity;
namespace Posechaemost.Data.Repository namespace Posechaemost.Data.Repository
{ {
public class GroupRepositoryImpl public class GroupRepositoryImpl: IGroupRepository
{ {
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity? UpdateGroup(String name) public bool AddGroup(String name, String id)
{ {
GroupLocalEntity? groupLocal = GetAllGroups() GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
.Where(x => x.Name == name).FirstOrDefault(); // GroupLocalEntity? group = new GroupLocalEntity();
if (groupLocal == null) return null;
groupLocal.Name = name; groupLocal.Name = name;
groupLocal.Id = int.Parse(id);
return true;
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
{
GroupLocalEntity groupLocal = GetAllGroups()
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return null;
return groupLocal; 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.Name = name;
groupLocal.Id = int.Parse(id); return true;
return groupLocal;
} }
} }
} }
// {
// public List<GroupLocalEntity> 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;
// }
// }

View File

@ -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<GroupLocalEntity> GetAllGroup();
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, String name);
GroupLocalEntity GetGroupById(int groupID);
bool AddGroup(String name, String id);
}
}

View File

@ -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<UserLocalEntity> GetAllUser();
bool RemoveUserByGuid(Guid userGuid);
UserLocalEntity? GetUserByGuid(Guid userGuid);
UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity);
UserLocalEntity? UpdateUserByGuid(Guid userGuid);
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Posechaemost.Data.LocalData; using Posechaemost.Data.LocalData;
@ -9,12 +8,18 @@ using Posechaemost.Data.LocalData.Entity;
namespace Posechaemost.Data.Repository namespace Posechaemost.Data.Repository
{ {
public class UserRepositoryImpl public class UserRepositoryImpl: IUserRepository
{ {
public UserRepositoryImpl() { public UserRepositoryImpl() {
GetAllUsers = LocalStaticData.users; GetAllUsers = LocalStaticData.users;
} }
public List<UserLocalEntity> GetAllUser()
{
throw new NotImplementedException();
}
public List<UserLocalEntity> GetAllUsers public List<UserLocalEntity> GetAllUsers
{ get; set; } { get; set; }

View File

@ -21,14 +21,10 @@ namespace Posechaemost.Domain.UseCase
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups() public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public Group UpdateGroupName(String name, String name1) { public bool UpdateGroupName(String id, String name1) {
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1);
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 GroupLocalEntity AddGroup(String name, String id) public bool AddGroup(String name, String id)
{ {
return _repositoryGroupImpl.AddGroup(name, id); return _repositoryGroupImpl.AddGroup(name, id);
} }

View File

@ -11,8 +11,9 @@ namespace Posechaemost.Domain.UseCase
{ {
public class UserUseCase public class UserUseCase
{ {
private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl; private readonly UserRepositoryImpl _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{ {
@ -20,10 +21,10 @@ namespace Posechaemost.Domain.UseCase
_repositoryGroupImpl = repositoryGroupImpl; _repositoryGroupImpl = repositoryGroupImpl;
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups() private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
.Join(_repositoryGroupImpl.GetAllGroups(), .Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupID, user => user.GroupID,
group => group.Id, group => group.Id,
(user, group) => (user, group) =>

View File

@ -7,4 +7,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>
</Project> </Project>

View File

@ -1,10 +1,19 @@
using Posechaemost.Data.Repository; using Posechaemost.Data.Repository;
using Posechaemost.Domain.UseCase; using Posechaemost.Domain.UseCase;
using Posechaemost.UI; using Posechaemost.UI;
using Microsoft.Extensions.DependencyInjection;
using System.Text.RegularExpressions;
IServiceCollection services = new ServiceCollection();
services
.AddSingleton<IGroupRepository, GroupRepositoryImpl>()
.AddSingleton<UserUseCase>();
var serviceProvider = services.BuildServiceProvider();
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); UserUseCase userUseCase = serviceProvider.GetService<UserUseCase>();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase);

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Создано классом WriteCodeFragment MSBuild. // Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +1 @@
7a59f60438c72dd05578b09f953c9ba9d3343469014f076958deeba098123188 c78a5718d92cc56f307f18b87610c16cd6bd4adb899ce2e54039bee5d3d6ceb2

View File

@ -42,6 +42,12 @@
"frameworks": { "frameworks": {
"net8.0": { "net8.0": {
"targetAlias": "net8.0", "targetAlias": "net8.0",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": {
"target": "Package",
"version": "[8.0.1, )"
}
},
"imports": [ "imports": [
"net461", "net461",
"net462", "net462",

View File

@ -1,11 +1,114 @@
{ {
"version": 3, "version": 3,
"targets": { "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": { "projectFileDependencyGroups": {
"net8.0": [] "net8.0": [
"Microsoft.Extensions.DependencyInjection >= 8.0.1"
]
}, },
"packageFolders": { "packageFolders": {
"/home/gara/.nuget/packages/": {} "/home/gara/.nuget/packages/": {}
@ -48,6 +151,12 @@
"frameworks": { "frameworks": {
"net8.0": { "net8.0": {
"targetAlias": "net8.0", "targetAlias": "net8.0",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": {
"target": "Package",
"version": "[8.0.1, )"
}
},
"imports": [ "imports": [
"net461", "net461",
"net462", "net462",

View File

@ -1,8 +1,11 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "3K0+oSHYQvE=", "dgSpecHash": "JxuWkwCqUKY=",
"success": true, "success": true,
"projectFilePath": "/home/gara/csharp/Posechaemost/Posechaemost.csproj", "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": [] "logs": []
} }