Untitled
unknown
plain_text
2 years ago
1.5 kB
9
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Application.ViewModels.Trains;
using Application.ViewModels.Workshops;
using AutoMapper;
using Core.Application;
using Core.Exceptions;
using Domain.Repositories.Trains;
using Domain.Repositories.Workshops;
namespace Application.Usecases.training.Get2
{
public class GetTrainByIDQuery : IQuery<TrainDTO>
{
public long TrainId { get; }
public GetTrainByIDQuery(long trainID)
{
this.TrainId = trainID;
}
}
public class GetTrainByIDQueryHandler : IQueryHandler<GetTrainByIDQuery,TrainDTO>
{
private readonly ITrainRepository trainRepository;
private readonly IMapper mapper;
public GetTrainByIDQueryHandler(ITrainRepository trainRepository, IMapper mapper)
{
this.trainRepository = trainRepository;
this.mapper = mapper;
}
public async Task<TrainDTO> Handle(GetTrainByIDQuery request, CancellationToken cancellationToken)
{
var train = await trainRepository.GetByIdAsync(request.TrainId);
if (train == null)
throw new DataNotFoundException();
var trainmodel = train.VirWorkShop.Where(x => x.TrainId == train.Id).ToList();
return mapper.Map<TrainDTO>(train);
}
}
}
Editor is loading...