34 lines
984 B
C#
34 lines
984 B
C#
using Domain.Entities;
|
|
using Domain.Interface;
|
|
using Infrastructure.Context;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Infrastructure.Repositories;
|
|
|
|
public class UserRepository(ApplicationDbContext applicationDbContext)
|
|
: GenericRepository<User>(applicationDbContext), IUserRepository
|
|
{
|
|
public async Task<User?> GetUserByEmailAsync(string email)
|
|
{
|
|
return await DbSet.FirstOrDefaultAsync(u => u.Email == email);
|
|
}
|
|
|
|
public async Task<User?> GetUserByUsernameAsync(string username)
|
|
{
|
|
return await DbSet.FirstOrDefaultAsync(u => u.Username == username);
|
|
}
|
|
|
|
public async Task<List<string>> GetUserRolesByEmailAsync(string email)
|
|
{
|
|
return await DbSet
|
|
.Where(ur => ur.Email == email)
|
|
.SelectMany(ur => ur.UserRoles)
|
|
.Select(ur => ur.Role!.Name)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<User?> GetUserByIdAsync(int id)
|
|
{
|
|
return await DbSet.FindAsync(id);
|
|
}
|
|
} |