41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SPMS.Domain.Entities;
|
|
using SPMS.Domain.Interfaces;
|
|
|
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
|
|
|
public class AdminRepository : Repository<Admin>, IAdminRepository
|
|
{
|
|
public AdminRepository(AppDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<Admin?> GetByEmailAsync(string email)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.Email == email && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<Admin?> GetByAdminCodeAsync(string adminCode)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.AdminCode == adminCode && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<Admin?> GetByRefreshTokenAsync(string refreshToken)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.RefreshToken == refreshToken && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<bool> EmailExistsAsync(string email, long? excludeId = null)
|
|
{
|
|
var query = _dbSet.Where(a => a.Email == email && !a.IsDeleted);
|
|
|
|
if (excludeId.HasValue)
|
|
query = query.Where(a => a.Id != excludeId.Value);
|
|
|
|
return await query.AnyAsync();
|
|
}
|
|
}
|