slarny4/Demo1/Data/Repository/UserRepositoryImpl.cs
2024-10-28 15:42:04 +03:00

65 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Demo.Domain.Models;
using Demo.Data.LocalData;
namespace Demo.Data.Repository
{
public class UserRepositoryImpl : IUserRepository
{
public IEnumerable<User> GetAllUsers()
{
return LocalStaticData.Users.Select(u => new User
{
Id = u.Id,
FIO = u.FIO,
GroupID = u.GroupID
});
}
public User GetUserById(Guid id)
{
var localUser = LocalStaticData.Users.FirstOrDefault(u => u.Id == id);
if (localUser == null)
throw new Exception("User not found");
return new User
{
Id = localUser.Id,
FIO = localUser.FIO,
GroupID = localUser.GroupID
};
}
public void AddUser(User user)
{
var localUser = new LocalData.Entity.User
{
Id = user.Id,
FIO = user.FIO,
GroupID = user.GroupID
};
LocalStaticData.Users.Add(localUser);
}
public void UpdateUser(User user)
{
var localUser = LocalStaticData.Users.FirstOrDefault(u => u.Id == user.Id);
if (localUser == null)
throw new Exception("User not found");
localUser.FIO = user.FIO;
localUser.GroupID = user.GroupID;
}
public void DeleteUser(Guid id)
{
var user = LocalStaticData.Users.FirstOrDefault(u => u.Id == id);
if (user != null)
{
LocalStaticData.Users.Remove(user);
}
}
}
}