Demo/Data/Repository/UserRepositorylmpl.cs
2024-10-17 14:46:19 +03:00

42 lines
1.4 KiB
C#

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; }
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];
}
}
}