banana
This commit is contained in:
parent
26da83afba
commit
efdaa78822
@ -1,5 +1,5 @@
|
||||
namespace Demo.Domain.Models{
|
||||
public class UserLocalEntity{
|
||||
public class UserLocalEntity :IEquatable<UserLocalEntity>{
|
||||
public required string FIO{get; set; }
|
||||
public Guid Guid {get; set; }
|
||||
public required int GroupID{get; set; }
|
||||
|
@ -1,12 +1,10 @@
|
||||
using Demo.Domain.Models;
|
||||
|
||||
using Demo.Data.LocalData;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class GroupRepositoryImpl
|
||||
public class GroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
// public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
||||
public GroupRepositoryImpl() {
|
||||
|
||||
GetAllGroups = LocalStaticData.groups;
|
||||
@ -14,18 +12,43 @@ namespace Demo.Data.Repository
|
||||
public List<GroupLocalEntity> GetAllGroups
|
||||
{ get; set; }
|
||||
|
||||
public void CreateNewGroup(GroupLocalEntity groupLocalEntity)
|
||||
public List<GroupLocalEntity> GetAllGroup()
|
||||
{
|
||||
GetAllGroups.Add(groupLocalEntity);
|
||||
return GetAllGroups;
|
||||
}
|
||||
|
||||
public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity)
|
||||
public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) {
|
||||
|
||||
if (GetAllGroups.Any(x => x.ID == groupCreateLocalEntity.ID)) return null;
|
||||
|
||||
GetAllGroups.Add(groupCreateLocalEntity);
|
||||
return groupCreateLocalEntity;
|
||||
}
|
||||
|
||||
public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup)
|
||||
{
|
||||
int index = GetAllGroups.FindIndex(x => x.ID == groupUpdateLocalEntity.ID);
|
||||
int index = GetAllGroups.FindIndex(x => x.ID == updatedGroup.ID);
|
||||
if (index == -1) return null;
|
||||
GetAllGroups[index].Name = groupUpdateLocalEntity.Name;
|
||||
GetAllGroups[index].Name = updatedGroup.Name;
|
||||
Console.WriteLine($"Обновленный Name: {GetAllGroups[index].Name}");
|
||||
return GetAllGroups[index];
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int groupId)
|
||||
{
|
||||
GroupLocalEntity? groupLocal = GetAllGroups
|
||||
.Where(x => x.ID == groupId).FirstOrDefault();
|
||||
if (groupLocal == null) return false;
|
||||
|
||||
return GetAllGroups.Remove(groupLocal);
|
||||
}
|
||||
|
||||
public GroupLocalEntity? GetGroupById(int groupId)
|
||||
{
|
||||
GroupLocalEntity? grouplocal = LocalStaticData.groups.Where(x => x.ID == groupId).FirstOrDefault();
|
||||
if (grouplocal == null) return null;
|
||||
|
||||
return grouplocal;
|
||||
}
|
||||
}
|
||||
}
|
13
Data/Repository/IGroupRepository.cs
Normal file
13
Data/Repository/IGroupRepository.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IGroupRepository
|
||||
{
|
||||
List<GroupLocalEntity> GetAllGroup();
|
||||
bool RemoveGroupById(int groupId);
|
||||
GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup);
|
||||
GroupLocalEntity? GetGroupById(int groupId);
|
||||
GroupLocalEntity? CreateGroup(GroupLocalEntity newGroup);
|
||||
}
|
||||
}
|
12
Data/Repository/IUserRepository.cs
Normal file
12
Data/Repository/IUserRepository.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
List<UserLocalEntity> GetAllUser();
|
||||
bool RemoveUserByGuid(Guid userGuid);
|
||||
UserLocalEntity? UpdateUserById(UserLocalEntity userUpdateLocalEntity);
|
||||
UserLocalEntity? GetUserById(Guid userGuid);
|
||||
}
|
||||
}
|
@ -12,6 +12,10 @@ namespace Demo.Data.Repository
|
||||
public List<UserLocalEntity> GetAllUsers
|
||||
{ get; set; }
|
||||
|
||||
public List<UserLocalEntity> GeAllUser(){
|
||||
return GetAllUsers;
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
|
BIN
Domain/.DS_Store
vendored
Normal file
BIN
Domain/.DS_Store
vendored
Normal file
Binary file not shown.
@ -5,20 +5,20 @@ namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class GroupUseCase
|
||||
{
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
private UserRepositoryImpl _repositoryUserImpl;
|
||||
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl, UserRepositoryImpl repositoryUserImpl)
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
|
||||
{
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
_repositoryUserImpl = repositoryUserImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
|
||||
|
||||
public bool CreateNewGroup(Group group){
|
||||
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{ID = group.ID, Name = group.Name};
|
||||
_repositoryGroupImpl.CreateNewGroup(groupLocalEntity);
|
||||
_repositoryGroupImpl.CreateGroup(groupLocalEntity);
|
||||
if (groupLocalEntity != null) return false;
|
||||
return true;
|
||||
}
|
||||
@ -41,5 +41,17 @@ namespace Demo.Domain.UseCase
|
||||
Name = result.Name
|
||||
};
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid) {
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
|
||||
public Group GetGroupById(int groupID)
|
||||
{
|
||||
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupID);
|
||||
if (groupLocalEntity == null) throw new Exception("bello");
|
||||
return new Group{
|
||||
ID = groupID, Name = groupLocalEntity.Name};
|
||||
}
|
||||
}
|
||||
}
|
13
Domain/UseCase/IGroupUseCase.cs
Normal file
13
Domain/UseCase/IGroupUseCase.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public interface IGroupUseCase
|
||||
{
|
||||
List<Group> GetAllGroups();
|
||||
bool RemoveUserByGuid(Guid userGuid);
|
||||
Group UpdateGroup(Group group);
|
||||
GroupLocalEntity GetGroupById(int groupId);
|
||||
bool CreateGroup(Group group);
|
||||
}
|
||||
}
|
12
Domain/UseCase/IUserUseCase.cs
Normal file
12
Domain/UseCase/IUserUseCase.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public interface IUserUseCase
|
||||
{
|
||||
List<User> GetAllUsers();
|
||||
bool RemoveUserByGuid(Guid userGuid);
|
||||
User UpdateUser(User user);
|
||||
User GetUserByGuid(Guid userGuid);
|
||||
}
|
||||
}
|
@ -5,20 +5,20 @@ namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase
|
||||
{
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
private UserRepositoryImpl _repositoryUserImpl;
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
|
||||
public UserUseCase(GroupRepositoryImpl repositoryGroupImpl, UserRepositoryImpl repositoryUserImpl)
|
||||
public UserUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
|
||||
{
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
_repositoryUserImpl = repositoryUserImpl;
|
||||
}
|
||||
|
||||
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups
|
||||
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
|
||||
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
|
||||
.Join(_repositoryGroupImpl.GetAllGroups,
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
||||
.Join(_repositoryGroupImpl.GetAllGroup(),
|
||||
user => user.GroupID,
|
||||
group => group.ID,
|
||||
(user, group) => new User{
|
||||
|
@ -13,7 +13,7 @@ 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+d5ff9f45a55af13593d3b8a9b65ecffccf59b0a7")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+26da83afbacb32e0747365acef2fa22c2343aec8")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Demo")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Demo")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
5bce74879fd45efe103c6f650dd3b5b74cc20c28f77d21ab4268da5f80b45640
|
||||
43ed596f37cf9f6f3388e175e6bccefd2309a85ded3d7b3c846b1dde41f188e3
|
||||
|
Loading…
Reference in New Issue
Block a user