49 lines
No EOL
1.2 KiB
C#
49 lines
No EOL
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SurveyBackend.Core.Models;
|
|
using SurveyBackend.Core.Repositories;
|
|
using SurveyBackend.Infrastructure.Data;
|
|
|
|
namespace SurveyBackend.Infrastructure.Repositories;
|
|
|
|
public class UserRepository : IUserRepository
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public UserRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<User?> GetByIdAsync(int id)
|
|
{
|
|
return await _context.Users.FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<User>> GetAllAsync()
|
|
{
|
|
return await _context.Users.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(User entity)
|
|
{
|
|
await _context.Users.AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(User entity)
|
|
{
|
|
_context.Users.Update(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(User entity)
|
|
{
|
|
_context.Users.Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<User?> GetUserByEmail(string email)
|
|
{
|
|
return await _context.Users.FirstOrDefaultAsync(u => u.Email == email);
|
|
}
|
|
} |