61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using Demo.Data.Exceptions;
|
|
using Demo.Data.RemoteData.RemoteDataBase;
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Demo.domain.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Demo.Data.Repository
|
|
{
|
|
public class SQLUserRepositoryImpl : IUserRepository
|
|
{
|
|
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
|
|
|
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext)
|
|
{
|
|
_remoteDatabaseContext = remoteDatabaseContext;
|
|
}
|
|
|
|
public IEnumerable<UserDao> GetAllUsersDao => _remoteDatabaseContext.Users;
|
|
|
|
public bool RemoveUserByIdDao(int userId)
|
|
{
|
|
var user = _remoteDatabaseContext.Users.FirstOrDefault(u => u.UserId == userId);
|
|
if (user == null) throw new UserNotFoundException(userId);
|
|
|
|
_remoteDatabaseContext.Users.Remove(user);
|
|
return true;
|
|
}
|
|
|
|
public UserDao? UpdateUserDao(UserDao user)
|
|
{
|
|
var existingUser = _remoteDatabaseContext.Users.FirstOrDefault(u => u.UserId == user.UserId);
|
|
if (existingUser == null) throw new UserNotFoundException(user.UserId);
|
|
|
|
existingUser.FIO = user.FIO;
|
|
existingUser.GroupId = user.GroupId;
|
|
|
|
return existingUser;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<UserLocalEnity> GetAllUsers => throw new NotImplementedException();
|
|
|
|
public bool RemoveUserById(int userId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public UserLocalEnity? UpdateUser(UserLocalEnity user)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|