This commit is contained in:
Class_Student 2024-10-18 11:32:27 +03:00
parent 120f2c3b16
commit 7b40532afd
8 changed files with 81 additions and 19 deletions

View File

@ -17,12 +17,12 @@ namespace _123.Data.LocalData
}; };
public static List<UserLocalEntity> users => new List<UserLocalEntity> public static List<UserLocalEntity> users => new List<UserLocalEntity>
{ {
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio", GroupID = 1 }, new UserLocalEntity{UserGuid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), UserFIO = "RandomFio", GroupID = 1 },
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio1", GroupID = 2 }, new UserLocalEntity{UserGuid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), UserFIO = "RandomFio1", GroupID = 2 },
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio2", GroupID = 3 }, new UserLocalEntity{UserGuid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), UserFIO = "RandomFio2", GroupID = 3 },
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio3", GroupID = 1 }, new UserLocalEntity{UserGuid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), UserFIO = "RandomFio3", GroupID = 1 },
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio4", GroupID = 2 }, new UserLocalEntity{UserGuid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), UserFIO = "RandomFio4", GroupID = 2 },
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio5", GroupID = 3 }, new UserLocalEntity{UserGuid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), UserFIO = "RandomFio5", GroupID = 3 },
}; };
public static List<PresenceLocalEntity> presences => new List<PresenceLocalEntity> public static List<PresenceLocalEntity> presences => new List<PresenceLocalEntity>
{ {

View File

@ -13,14 +13,17 @@ namespace _123.Data.ReportsHistory
{ {
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups; public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity) public GroupLocalEntity? UpdateGroup(String name)
{ {
GroupLocalEntity? groupLocal = GetAllGroups() GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.ID == groupUpdateLocalEntity.ID).FirstOrDefault(); .Where(x => x.Name == name).FirstOrDefault();
if (groupLocal == null) return null; if (groupLocal == null) return null;
groupLocal.ID = groupUpdateLocalEntity.ID; groupLocal.Name = name;
groupLocal.Name = groupUpdateLocalEntity.Name;
return groupLocal; return groupLocal;
} }
//public GroupLocalEntity AddGroup(String name, String id)
//{
// List<GroupLocalEntity> groups => new List<GroupLocalEntity>
//}
} }
} }

View File

@ -27,6 +27,14 @@ namespace _123.Data.ReportsHistory
return GetAllUsers.Remove(userLocal); return GetAllUsers.Remove(userLocal);
} }
public UserLocalEntity FindUserByGuid(Guid userGuid)
{
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) throw new Exception("Пользователь не найден");
return userLocal;
}
public UserLocalEntity? GetUserByGuid(Guid userGuid) public UserLocalEntity? GetUserByGuid(Guid userGuid)
{ {
@ -47,5 +55,14 @@ namespace _123.Data.ReportsHistory
return userLocal; return userLocal;
} }
public UserLocalEntity? UpdateUserByGuid(Guid userGuid)
{
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.UserGuid == userGuid).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
}
} }
} }

View File

@ -19,14 +19,13 @@ namespace _123.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(Group grou) public Group UpdateGroupName(String name, String name1)
{ {
GroupLocalEntity groupLocalEntity = new GroupLocalEntity { ID = grou.ID, Name = grou.Name }; GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name);
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
if (result == null) throw new Exception(""); if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.ID); Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result!.Name);
if (group == null) throw new Exception(""); if (group == null) throw new Exception("");
return new Group { ID = group.ID, Name = group.Name }; return new Group { ID = group.ID, Name = name1 };
} }
} }

View File

@ -48,6 +48,17 @@ namespace _123.Domain.UseCase
if (group == null) throw new Exception(""); if (group == null) throw new Exception("");
return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group }; return new User { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group };
} }
public UserLocalEntity FindUserByGuid(Guid userGuid)
{
return _repositoryUserImpl.FindUserByGuid(userGuid);
}
public UserLocalEntity UpdateUserByGuid(Guid userGuid, String name, String gro)
{
UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == int.Parse(gro));
if (group == null) throw new Exception("");
return new UserLocalEntity { UserFIO = name, GroupID = int.Parse(gro), UserGuid = userGuid};
}
} }
} }

View File

@ -1,3 +1,5 @@
using _123.Data.LocalData.Entity;
using _123.Domain.Models;
using _123.Domain.UseCase; using _123.Domain.UseCase;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,5 +24,14 @@ namespace _123.UI
} }
Console.WriteLine(groupOutput); Console.WriteLine(groupOutput);
} }
public void UpdateGroupName(String name, String name1)
{
StringBuilder groupOutput = new StringBuilder();
var group = _groupUseCase.UpdateGroupName(name,name1);
{
groupOutput.AppendLine($"{group.Name}\t{group.ID}");
}
Console.WriteLine(groupOutput);
}
} }
} }

View File

@ -32,7 +32,9 @@ namespace _123.UI
case "1": _userConsoleUI.DisplayAllUsers(); break; case "1": _userConsoleUI.DisplayAllUsers(); break;
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break; case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "3": _groupConsoleUI.DisplayAllGroups(); break; case "3": _groupConsoleUI.DisplayAllGroups(); break;
case "4": _userConsoleUI.FindUserByGuid(Guid.Parse(Console.ReadLine()));break;
case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()),Console.ReadLine(), Console.ReadLine()); break;
case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(),Console.ReadLine()); break;
default: default:
DisplayMenu(); DisplayMenu();
break; break;

View File

@ -1,4 +1,6 @@
using _123.Domain.UseCase; using _123.Data.LocalData.Entity;
using _123.Domain.Models;
using _123.Domain.UseCase;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -31,6 +33,23 @@ namespace _123.UI
} }
Console.WriteLine(userOutput); Console.WriteLine(userOutput);
} }
public void FindUserByGuid (Guid guidUser)
{
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.FindUserByGuid(guidUser);
{
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}");
}
Console.WriteLine(userOutput);
}
public void UpdateUserByGuid(Guid userGuid,String name,String group)
{
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.UpdateUserByGuid(userGuid,name,group);
{
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.GroupID}");
}
Console.WriteLine(userOutput);
}
} }
} }