Demo/Data/Repository/UserRepositorylmpl.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2024-10-17 11:46:19 +00:00
using Demo.Domain.Models;
using Demo.Data.LocalData;
namespace Demo.Data.Repository
{
public class UserRepositoryImpl
{
public UserRepositoryImpl() {
GetAllUsers = LocalStaticData.users;
}
public List<UserLocalEntity> GetAllUsers
{ get; set; }
2024-10-21 09:38:07 +00:00
public List<UserLocalEntity> GeAllUser(){
return GetAllUsers;
}
2024-10-17 11:46:19 +00:00
public bool RemoveUserByGuid(Guid userGuid)
{
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userGuid).FirstOrDefault();
if (userLocal == null) return false;
return GetAllUsers.Remove(userLocal);
}
public UserLocalEntity? GetUserById(Guid userGuid)
{
UserLocalEntity? userlocal = LocalStaticData.users.Where(x => x.Guid == userGuid).FirstOrDefault();
if (userlocal == null) return null;
return userlocal;
}
public UserLocalEntity? UpdateUserById(UserLocalEntity userUpdateLocalEntity)
{
int index = GetAllUsers.FindIndex(x => x.Guid == userUpdateLocalEntity.Guid);
if (index == -1) return null;
GetAllUsers[index].FIO = userUpdateLocalEntity.FIO;
GetAllUsers[index].GroupID = userUpdateLocalEntity.GroupID;
Console.WriteLine($"Обновленный FIO: {GetAllUsers[index].FIO}, GroupID: {GetAllUsers[index].GroupID}");
return GetAllUsers[index];
}
}
}