public override async Task OnDisconnected(bool stopCalled) { if (!string.IsNullOrWhiteSpace(_serviceRequestId)) { await _onlineUserOperations.DeleteOnlineUserAsync(_userHttpContext.HttpContext.User.GetCurrentUserDetails().Email); await UpdateServiceRequestClients(); } await base.OnDisconnected(stopCalled); }
public async Task <IActionResult> MarkOfflineUser() { // Delete the current logged in user from OnlineUsers entity await _onlineUsersOperations.DeleteOnlineUserAsync(HttpContext.User.GetCurrentUserDetails().Email); string serviceRequestId = HttpContext.Request.Headers["ServiceRequestId"]; // Get Service Request Details var serviceRequest = await _serviceRequestOperations.GetServiceRequestByRowKey(serviceRequestId); // Get Customer and Service Engineer names var customerName = (await _userManager.FindByEmailAsync(serviceRequest.PartitionKey)).UserName; var serviceEngineerName = (await _userManager.FindByEmailAsync(serviceRequest.ServiceEngineer)).UserName; var adminName = (await _userManager.FindByEmailAsync(_options.Value.AdminEmail)).UserName; // check Admin, Service Engineer and customer are connected. var isAdminOnline = await _onlineUsersOperations.GetOnlineUserAsync(_options.Value.AdminEmail); var isServiceEngineerOnline = await _onlineUsersOperations.GetOnlineUserAsync(serviceRequest.ServiceEngineer); var isCustomerOnline = await _onlineUsersOperations.GetOnlineUserAsync(serviceRequest.PartitionKey); List <string> users = new List <string>(); if (isAdminOnline) { users.Add(adminName); } if (isServiceEngineerOnline) { users.Add(serviceEngineerName); } if (isCustomerOnline) { users.Add(customerName); } // Send notifications _signalRConnectionManager.GetHubContext <ServiceMessagesHub>() .Clients .Users(users) .online(new { isAd = isAdminOnline, isSe = isServiceEngineerOnline, isCu = isCustomerOnline }); return(Json(true)); }