2024-11-10 18:56:16 +00:00
|
|
|
|
using Demo.Data.Exceptions;
|
|
|
|
|
using Demo.Data.LocalData;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
using Demo.domain.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public class UserRepositoryImpl : IUserRepository
|
2024-10-16 08:22:40 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
private List<UserLocalEnity> _users;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public UserRepositoryImpl()
|
|
|
|
|
{
|
|
|
|
|
_users = LocalStaticData.users;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public IEnumerable<UserLocalEnity> GetAllUsers => _users;
|
|
|
|
|
|
|
|
|
|
public bool RemoveUserById(Guid userGuid) // Оставил Guid
|
2024-10-16 08:22:40 +00:00
|
|
|
|
{
|
2024-11-10 18:56:16 +00:00
|
|
|
|
var user = _users.FirstOrDefault(u => u.Guid == userGuid);
|
|
|
|
|
if (user == null) throw new UserNotFoundException(userGuid);
|
2024-10-16 08:22:40 +00:00
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
_users.Remove(user);
|
|
|
|
|
return true;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
public UserLocalEnity? UpdateUser(UserLocalEnity user)
|
|
|
|
|
{
|
|
|
|
|
var existingUser = _users.FirstOrDefault(u => u.Guid == user.Guid);
|
|
|
|
|
if (existingUser == null) throw new UserNotFoundException(user.Guid);
|
2024-10-16 08:22:40 +00:00
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
existingUser.FIO = user.FIO;
|
|
|
|
|
existingUser.GroupID = user.GroupID;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
|
2024-11-10 18:56:16 +00:00
|
|
|
|
return existingUser;
|
2024-10-16 08:22:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|