private async Task UpdateServiceRequestClients()
        {
            // Get Hub Context
            var hubContext = _signalRConnectionManager.GetHubContext <ServiceMessagesHub>();

            // 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 = string.Empty;

            if (!string.IsNullOrWhiteSpace(serviceRequest.ServiceEngineer))
            {
                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 _onlineUserOperations.GetOnlineUserAsync(_options.Value.AdminEmail);

            var isServiceEngineerOnline = false;

            if (!string.IsNullOrWhiteSpace(serviceRequest.ServiceEngineer))
            {
                isServiceEngineerOnline = await _onlineUserOperations.GetOnlineUserAsync(serviceRequest.ServiceEngineer);
            }
            var isCustomerOnline = await _onlineUserOperations.GetOnlineUserAsync(serviceRequest.PartitionKey);


            List <string> users = new List <string>();

            if (isAdminOnline)
            {
                users.Add(adminName);
            }
            if (!string.IsNullOrWhiteSpace(serviceEngineerName))
            {
                if (isServiceEngineerOnline)
                {
                    users.Add(serviceEngineerName);
                }
            }
            if (isCustomerOnline)
            {
                users.Add(customerName);
            }


            hubContext
            .Clients
            .Users(users)
            .online(new
            {
                isAd = isAdminOnline,
                isSe = isServiceEngineerOnline,
                isCu = isCustomerOnline
            });
        }
        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));
        }