network-resurrector/NetworkResurrector.Agent.Ap.../Queries/GetMachines.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2020-12-23 01:27:39 +02:00
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)
{
2020-12-23 01:43:12 +02:00
var machines = await _repository.GetMachines();
var result = _mapper.Map<Model[]>(machines);
2020-12-23 01:27:39 +02:00
return result;
}
}
}
}