using AutoMapper; using MediatR; using NDB.Application.DataContracts; using NetworkResurrector.Application.Services; using System; using System.Threading; using System.Threading.Tasks; namespace NetworkResurrector.Application.Queries { public class GetToken { public class Query : Query { public string UserName { get; set; } public string Password { get; set; } public Query() { } } public class Model { public string Token { get; set; } public DateTime ValidUntil { get; set; } } public class QueryHandler : IRequestHandler { private readonly IUserService _userService; private readonly IMapper _mapper; public QueryHandler(IUserService userService, IMapper mapper) { _userService = userService; _mapper = mapper; } public async Task Handle(Query request, CancellationToken cancellationToken) { var securityToken = await _userService.Login(request.UserName, request.Password); if (securityToken == null) return null; var result = _mapper.Map(securityToken); return result; } } } }