private bool SendSignalRToast(Toast toast, ConnectedUser connectedUser, IHubContext context)
 {
     try
     {
         context.Clients.Client(connectedUser.Id).toastMessage(toast.Name, toast.Message);
         UpdateNotificationsBadgeNum(connectedUser, context);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 private void UpdateNotificationsBadgeNum(ConnectedUser connectedUser,IHubContext context)
 {
     var orgStore = GetOrgStore(connectedUser.OrgKey);
     if (orgStore == null) return;
     using (var session = orgStore.OpenSession())
     {
         var res =
             session.Query<UnreadNotificationsforUser.ReduceResult, UnreadNotificationsforUser>()
                    .FirstOrDefault(r => r.UserId == connectedUser.UserId);
         if (res != null)
         {
             context.Clients.Client(connectedUser.Id).setNumUnreadNotifications(res.Count+1); 
         }
             
     }
 }
        public override Task OnConnected()
        {
            
            var ci = Context.User.Identity as ClaimsIdentity;
            if (ci == null)
            {
                return base.OnConnected();
            }
            
            var orgKeyClaim = ci.FindFirst(c => c.Type == IlluminateClaimTypes.OrgKey);
            var userIdClaim = ci.FindFirst(c => c.Type == IlluminateClaimTypes.UserId);
            if (orgKeyClaim != null && userIdClaim != null)
            {
                using (var session = MvcApplication.DataBase.MasterStore.OpenSession())
                {
                    var connectedUser = new ConnectedUser
                                            {
                                                ConnectedAt = DateTime.Now,
                                                Id = Context.ConnectionId,
                                                OrgKey = orgKeyClaim.Value.ToLower(),
                                                UserId = userIdClaim.Value
                                            };
                    session.Store(connectedUser);
                    try
                    {
                        session.SaveChanges();
                    }
                    catch (OutOfMemoryException)
                    {

                    }
                }
            }
               
            
            return base.OnConnected();
        }