refactor: move database-related projects to separate folder
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
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.LectureHall.Queries.GetLectureHallList;
|
||||
|
||||
public class GetLectureHallListQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallListQuery, LectureHallListVm>
|
||||
{
|
||||
public async Task<LectureHallListVm> Handle(GetLectureHallListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.LectureHalls.OrderBy(l => l.Id).Select(l => new LectureHallLookupDto()
|
||||
{
|
||||
Id = l.Id,
|
||||
Name = l.Name,
|
||||
CampusId = l.CampusId
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new LectureHallListVm
|
||||
{
|
||||
LectureHalls = result
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user