presence/data/Repository/UserRepositoryImpl.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2024-11-13 09:00:26 +00:00
using data.Exception;
2024-11-11 09:07:11 +00:00
using data.LocalData;
using data.RemoteData.RemoteDataBase.DAO;
using domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace data.Repository
{
public class UserRepositoryImpl : IUserRepository
{
private List<UserLocalEnity> _users;
public UserRepositoryImpl()
{
_users = LocalStaticData.users;
}
public IEnumerable<UserLocalEnity> GetAllUsers => _users;
2024-11-13 09:00:26 +00:00
public bool RemoveUserByGuid(Guid userGuid)
2024-11-11 09:07:11 +00:00
{
var user = _users.FirstOrDefault(u => u.Guid == userGuid);
if (user == null) throw new UserNotFoundException(userGuid);
_users.Remove(user);
return true;
}
public UserLocalEnity? UpdateUser(UserLocalEnity user)
{
var existingUser = _users.FirstOrDefault(u => u.Guid == user.Guid);
if (existingUser == null) throw new UserNotFoundException(user.Guid);
existingUser.FIO = user.FIO;
existingUser.GroupID = user.GroupID;
return existingUser;
}
public List<UserDao> GetUserNames()
{
return _users
.Select(u => new UserDao
{
Guid = u.Guid,
FIO = u.FIO
})
.ToList();
}
}
}