0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-07-05 21:43:56 +00:00
CleanArchitecture/CleanArchitecture.Application/Queries/Tenants/GetAll/GetAllTenantsQueryHandler.cs
2023-08-30 23:31:47 +02:00

33 lines
1.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CleanArchitecture.Application.ViewModels.Tenants;
using CleanArchitecture.Domain.Interfaces.Repositories;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CleanArchitecture.Application.Queries.Tenants.GetAll;
public sealed class GetAllTenantsQueryHandler :
IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantViewModel>>
{
private readonly ITenantRepository _tenantRepository;
public GetAllTenantsQueryHandler(ITenantRepository tenantRepository)
{
_tenantRepository = tenantRepository;
}
public async Task<IEnumerable<TenantViewModel>> Handle(
GetAllTenantsQuery request,
CancellationToken cancellationToken)
{
return await _tenantRepository
.GetAllNoTracking()
.Include(x => x.Users)
.Where(x => !x.Deleted)
.Select(x => TenantViewModel.FromTenant(x))
.ToListAsync(cancellationToken);
}
}