presence/Demo/Data/Repository/UserRepositoryImpl.cs

55 lines
1.4 KiB
C#
Raw Normal View History

2024-10-21 12:41:56 +00:00
using Demo.Data.Exceptions;
using Demo.Data.LocalData;
2024-10-25 08:47:11 +00:00
using Demo.Data.RemoteData.RemoteDataBase.DAO;
2024-10-21 12:41:56 +00:00
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
2024-10-25 08:47:11 +00:00
public class UserRepositoryImpl: IUserRepository
2024-10-21 12:41:56 +00:00
{
private List<UserLocalEnity> _users;
public UserRepositoryImpl()
{
_users = LocalStaticData.users;
}
public IEnumerable<UserLocalEnity> GetAllUsers => _users;
2024-10-25 08:47:11 +00:00
public IEnumerable<UserDao> GetAllUsersDao => throw new NotImplementedException();
2024-10-21 12:41:56 +00:00
public bool RemoveUserById(int userId)
{
var user = _users.FirstOrDefault(u => u.ID == userId);
if (user == null) throw new UserNotFoundException(userId);
_users.Remove(user);
return true;
}
2024-10-25 08:47:11 +00:00
public bool RemoveUserByIdDao(int userId)
{
throw new NotImplementedException();
}
2024-10-21 12:41:56 +00:00
public UserLocalEnity? UpdateUser(UserLocalEnity user)
{
var existingUser = _users.FirstOrDefault(u => u.Guid == user.Guid);
if (existingUser == null) throw new UserNotFoundException(user.ID);
existingUser.FIO = user.FIO;
existingUser.GroupID = user.GroupID;
return existingUser;
}
2024-10-25 08:47:11 +00:00
public UserDao? UpdateUserDao(UserDao user)
{
throw new NotImplementedException();
}
2024-10-21 12:41:56 +00:00
}
}