public class DriversHub:Hub
{
private IDriversServices _driversServices;
private ILogger<DriversHub> _logger;
public DriversHub(IDriversServices driversServices, ILogger<DriversHub> logger)
{
_driversServices = driversServices;
_logger = logger;
}
public override async Task OnConnectedAsync()
{
var userName = Context.User?.Claims.FirstOrDefault(x => x.Type == "email")?.Value;
if (!string.IsNullOrEmpty(userName))
await Groups.AddToGroupAsync(Context.ConnectionId, userName);
await base.OnConnectedAsync();
}
public async Task GetDriversDetail(string number)
{
var model = new Data.Model.GetDriverInformationModel { Number = number};
try
{
DriverInfo info = new DriverInfo();
info = (await _driversServices.GetDriverInformation(model)).ToList();
await Clients.Users(number).SendAsync("OnGetDriverDetails"/*, dest*/, Factory.OkResponse(info));
}
catch (Exception ex)
{
_logger.LogException(ex, model);
}
}
}