40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
|
using Demo.Data.LocalData;
|
|||
|
using Demo.Data.LocalData.Entity;
|
|||
|
using Demo.Domain.Models;
|
|||
|
using Demo.Domain.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace Demo.Data.Repository
|
|||
|
{
|
|||
|
public class UserRepositoryImpl
|
|||
|
{
|
|||
|
private List<LocalUser> users;
|
|||
|
|
|||
|
public UserRepositoryImpl()
|
|||
|
{
|
|||
|
users = LocalStaticData.Users; // Инициализируем пользователей из статических данных
|
|||
|
}
|
|||
|
|
|||
|
public List<User> GetAllUsers()
|
|||
|
{
|
|||
|
return users.Select(u => (User)u).ToList();
|
|||
|
}
|
|||
|
|
|||
|
public User GetUserById(Guid userId) // Изменено на Guid
|
|||
|
{
|
|||
|
var entityUser = users.FirstOrDefault(u => u.Id == userId);
|
|||
|
if (entityUser == null) throw new InvalidOperationException("User not found");
|
|||
|
|
|||
|
return (User)entityUser;
|
|||
|
}
|
|||
|
|
|||
|
public void AddUser(LocalUser user)
|
|||
|
{
|
|||
|
if (user == null) throw new ArgumentNullException(nameof(user));
|
|||
|
users.Add(user);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|