48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using AutoMapper;
|
|
using MediatR;
|
|
using NDB.Application.DataContracts;
|
|
using NetworkResurrector.Agent.Domain.Repositories;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NetworkResurrector.Agent.Application.Queries
|
|
{
|
|
public class GetMachines
|
|
{
|
|
public class Query : Query<Model[]>
|
|
{
|
|
public Query() { }
|
|
}
|
|
|
|
public class Model
|
|
{
|
|
public int MachineId { get; set; }
|
|
public string MachineName { get; set; }
|
|
public string FullMachineName { get; set; }
|
|
public string MACAddress { get; set; }
|
|
public string IPv4Address { get; set; }
|
|
public string Description { get; set; }
|
|
}
|
|
|
|
public class QueryHandler : IRequestHandler<Query, Model[]>
|
|
{
|
|
private readonly IAgentRepository _repository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public QueryHandler(IAgentRepository repository, IMapper mapper)
|
|
{
|
|
_repository = repository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<Model[]> Handle(Query request, CancellationToken cancellationToken)
|
|
{
|
|
var machines = await _repository.GetMachines();
|
|
var result = _mapper.Map<Model[]>(machines);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|