50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Demo.Data.Repository
|
|
{
|
|
public class SQLUserRepositoryImpl : IUserRepository
|
|
{
|
|
private readonly DbContext _context;
|
|
|
|
public SQLUserRepositoryImpl(DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IEnumerable<User> GetAllUsers()
|
|
{
|
|
return _context.Set<User>().ToList();
|
|
}
|
|
|
|
public User GetUserById(Guid id)
|
|
{
|
|
return _context.Set<User>().Find(id);
|
|
}
|
|
|
|
public void UpdateUser(User user)
|
|
{
|
|
_context.Set<User>().Update(user);
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
public void DeleteUser(Guid id)
|
|
{
|
|
var user = _context.Set<User>().Find(id);
|
|
if (user != null)
|
|
{
|
|
_context.Set<User>().Remove(user);
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public void AddUser(User user)
|
|
{
|
|
_context.Set<User>().Add(user);
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
} |