add update
This commit is contained in:
parent
185d423698
commit
0b9580781c
@ -10,7 +10,7 @@ namespace Demo.Data.LocalData
|
||||
{
|
||||
public static class LocalStaticData
|
||||
{
|
||||
public static IEnumerable<GroupLocalEntity> groups => new List<GroupLocalEntity>
|
||||
public static List<GroupLocalEntity> groups => new List<GroupLocalEntity>
|
||||
|
||||
{
|
||||
new GroupLocalEntity{ Id = 1, Name = "ИП1-21" },
|
||||
|
15
Demo/Data/Repository/GroupRepositoryImpl.cs
Normal file
15
Demo/Data/Repository/GroupRepositoryImpl.cs
Normal file
@ -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<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace Demo.Data.Repository
|
||||
{
|
||||
public class UserRepositoryImpl
|
||||
{
|
||||
public IEnumerable<UserLocalEnity> GetAllUsers() => LocalStaticData.users;
|
||||
public List<UserLocalEnity> GetAllUsers() => LocalStaticData.users;
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
@ -31,7 +31,7 @@ namespace Demo.Data.Repository
|
||||
return userLocal;
|
||||
}
|
||||
|
||||
public UserLocalEnity? UpdateUserByGuid(UserLocalEnity userUpdateLocalEnity) {
|
||||
public UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity) {
|
||||
UserLocalEnity? userLocal = LocalStaticData
|
||||
.users
|
||||
.Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Demo.Data.Repository;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,12 +10,34 @@ namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase
|
||||
{
|
||||
private UserRepositoryImpl _repositoryImpl;
|
||||
private UserRepositoryImpl _repositoryUserImpl;
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
|
||||
public UserUseCase(UserRepositoryImpl repositoryImpl)
|
||||
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryImpl = repositoryImpl;
|
||||
_repositoryUserImpl = repositoryImpl;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
||||
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
||||
public List<User> 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 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};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,20 @@
|
||||
|
||||
|
||||
using Demo.Data.Repository;
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
|
||||
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
|
||||
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
|
||||
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
|
||||
|
||||
List<User> users = userUseCase.GetAllUsers;
|
||||
|
||||
foreach (var user in users) {
|
||||
Console.WriteLine($"{user.FIO} группа {user.Group.Name}");
|
||||
}
|
||||
|
||||
userUseCase.
|
||||
|
||||
|
||||
Console.ReadKey();
|
Loading…
Reference in New Issue
Block a user