first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using Fitness_core_BE.Interfaces;
|
||||
using Fitness_core_BE.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Fitness_core_BE.Repos
|
||||
{
|
||||
public class AdminClientDirectoryRepository : IAdminClientDirectoryRepository
|
||||
{
|
||||
private readonly CentralDbContext _context;
|
||||
|
||||
public AdminClientDirectoryRepository(CentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<(List<Client> Items, int Total)> ListAsync(string? search, int page, int pageSize, CancellationToken ct = default)
|
||||
{
|
||||
var query = _context.Client
|
||||
.AsNoTracking()
|
||||
.Include(c => c.ClientBusinesses)
|
||||
.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
query = query.Where(c => c.ClientName != null && c.ClientName.Contains(search));
|
||||
|
||||
var total = await query.CountAsync(ct);
|
||||
|
||||
var items = await query
|
||||
.OrderBy(c => c.ClientName)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync(ct);
|
||||
|
||||
return (items, total);
|
||||
}
|
||||
|
||||
public async Task<Client?> GetByIdAsync(Guid clientId, CancellationToken ct = default)
|
||||
{
|
||||
return await _context.Client
|
||||
.AsNoTracking()
|
||||
.Include(c => c.ClientBusinesses)
|
||||
.FirstOrDefaultAsync(c => c.ClientId == clientId, ct);
|
||||
}
|
||||
|
||||
public async Task<bool> ClientExistsAsync(Guid clientId, CancellationToken ct = default)
|
||||
{
|
||||
return await _context.Client
|
||||
.AsNoTracking()
|
||||
.AnyAsync(c => c.ClientId == clientId, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user