slarny4/Demo1/Data/Repository/UserRepositoryImpl.cs
atabidze105 ad36f40a57 init
2024-10-24 11:50:32 +03:00

64 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AttendanceApp.Data.Exceptions;
using AttendanceApp.Data.LocalData;
using AttendanceApp.Domain.Models;
namespace AttendanceApp.Data.Repository
{
public class UserRepositoryImpl : IUserRepository
{
private readonly List<LocalUser> _users = LocalStaticData.Users;
public IEnumerable<User> GetAllUsers()
{
return _users.Select(u => new User
{
Id = u.Id,
FIO = u.FIO,
GroupId = u.GroupID
});
}
public User GetUserById(Guid id)
{
var localUser = _users.FirstOrDefault(u => u.Id == id);
if (localUser == null)
throw new UserNotFoundException($"Пользователь с ID {id} не найден.");
return new User
{
Id = localUser.Id,
FIO = localUser.FIO,
GroupId = localUser.GroupID
};
}
public void AddUser(User user)
{
_users.Add(new LocalUser
{
Id = user.Id,
FIO = user.FIO,
GroupID = user.GroupId
});
}
public void UpdateUser(User user)
{
var localUser = _users.FirstOrDefault(u => u.Id == user.Id);
if (localUser == null)
throw new UserNotFoundException($"Пользователь с ID {user.Id} не найден.");
localUser.FIO = user.FIO;
localUser.GroupID = user.GroupId;
}
public void DeleteUser(Guid id)
{
var user = _users.FirstOrDefault(u => u.Id == id);
if (user == null)
throw new UserNotFoundException($"Пользователь с ID {id} не найден.");
_users.Remove(user);
}
}
}