initial commit
This commit is contained in:
33
Infrastructure/Repositories/UserRepository.cs
Normal file
33
Infrastructure/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Application.Interfaces.Repositories;
|
||||
using Domain.Entities;
|
||||
using Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Repositories;
|
||||
|
||||
public class UserRepository(AppDbContext context) : IUserRepository
|
||||
{
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
return context.Users.AsNoTracking();
|
||||
}
|
||||
|
||||
public bool TryGetUserById(int id, out User? user)
|
||||
{
|
||||
user = context.Users.FirstOrDefault(u => u.Id == id);
|
||||
return user != null;
|
||||
}
|
||||
|
||||
public bool AddUser(User user)
|
||||
{
|
||||
context.Users.Add(user);
|
||||
return context.SaveChanges() != 0;
|
||||
}
|
||||
|
||||
public bool UpdateUser(User user)
|
||||
{
|
||||
context.Users.Update(user);
|
||||
return context.SaveChanges() != 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user