MireaBackend/SqlData/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs

26 lines
880 B
C#
Raw Normal View History

2024-01-28 04:31:18 +03:00
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
public class GetCampusBasicInfoListQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusBasicInfoListQuery, CampusBasicInfoVm>
{
public async Task<CampusBasicInfoVm> Handle(GetCampusBasicInfoListQuery request, CancellationToken cancellationToken)
{
var dtos = await dbContext.Campuses.Select(c => new CampusBasicInfoDto()
{
Id = c.Id,
CodeName = c.CodeName,
FullName = c.FullName
}).ToListAsync(cancellationToken);
return new CampusBasicInfoVm
{
Campuses = dtos
};
}
}