2024-11-25 04:33:26 +00:00
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
2024-10-28 12:42:04 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Data.Repository
|
|
|
|
|
{
|
|
|
|
|
public class SQLUserRepositoryImpl : IUserRepository
|
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
private readonly DbContext _context;
|
2024-10-28 12:42:04 +00:00
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public SQLUserRepositoryImpl(DbContext context)
|
2024-10-28 12:42:04 +00:00
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public IEnumerable<User> GetAllUsers()
|
2024-10-28 12:42:04 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
return _context.Set<User>().ToList();
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public User GetUserById(Guid id)
|
2024-10-28 12:42:04 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
return _context.Set<User>().Find(id);
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public void UpdateUser(User user)
|
2024-10-28 12:42:04 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
_context.Set<User>().Update(user);
|
|
|
|
|
_context.SaveChanges();
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteUser(Guid id)
|
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
var user = _context.Set<User>().Find(id);
|
|
|
|
|
if (user != null)
|
2024-10-28 12:42:04 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
_context.Set<User>().Remove(user);
|
2024-10-28 12:42:04 +00:00
|
|
|
|
_context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-14 11:24:07 +00:00
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
public void AddUser(User user)
|
2024-11-14 11:24:07 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
_context.Set<User>().Add(user);
|
|
|
|
|
_context.SaveChanges();
|
2024-11-14 11:24:07 +00:00
|
|
|
|
}
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|