network-resurrector/NetworkResurrector.Application/Queries/GetToken.cs

43 lines
1.0 KiB
C#
Raw Normal View History

2020-07-09 02:32:35 +03:00
using AutoMapper;
using MediatR;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace NetworkResurrector.Application.Queries
{
public class GetToken
{
public class Query : Query<Model>
{
public string UserName { get; set; }
public string Password { get; set; }
public Query() { }
}
public class Model
{
public Guid Token { get; set; }
public DateTime ValidUntil { get; set; }
}
public class QueryHandler : IRequestHandler<Query, Model>
{
private readonly IMapper _mapper;
public QueryHandler(IMapper mapper)
{
_mapper = mapper;
}
public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
{
var result = _mapper.Map<Model>(new { Token = Guid.NewGuid(), ValidUntil = DateTime.Now });
return result;
}
}
}
}