Demo/Data/Repository/UserRepositorylmpl.cs
2024-10-21 13:55:18 +03:00

46 lines
1.5 KiB
C#

using Demo.Domain.Models;
using Demo.Data.LocalData;
namespace Demo.Data.Repository
{
public class UserRepositoryImpl : IUserRepository
{
public UserRepositoryImpl() {
GetAllUsers = LocalStaticData.users;
}
public List<UserLocalEntity> GetAllUsers
{ get; set; }
public List<UserLocalEntity> GetAllUser(){
return GetAllUsers;
}
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];
}
}
}