Example #1
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var disconnectedUser = ConnectedClients.FirstOrDefault(x => x.Id.Equals(Context.ConnectionId));

            ConnectedClients.Remove(disconnectedUser);

            using (var _contextDB = new db_chatjobsityEntities())
            {
                var _objDb_disco = new Disconnected()
                {
                    UserID    = disconnectedUser.UserName,
                    Fe_Salida = System.DateTime.UtcNow.AddHours(-5)
                };
                _contextDB.Disconnected.Add(_objDb_disco);
                _contextDB.SaveChanges();

                var _discoUser = (from x in _contextDB.Disconnected
                                  orderby x.Fe_Salida descending
                                  select x).AsEnumerable().Take(50);
                var _discoUserX = (from x in _discoUser
                                   select new { UserName = x.Fe_Salida.ToString("yyyy-MM-dd HH:mm:ss") + " - " + x.UserID.ToString() }).ToList();

                Clients.All.updateUsers(ConnectedClients.Count(), ConnectedClients.Select(x => x.UserName), _discoUserX.Select(x => x.UserName));
            }
            return(base.OnDisconnected(stopCalled));
        }
Example #2
0
        public void Connect(string _username)
        {
            Client c = new Client()
            {
                UserName = _username,
                Id       = Context.ConnectionId
            };

            ConnectedClients.Add(c);
            using (var _contextDB = new db_chatjobsityEntities())
            {
                var _discoUser = (from x in _contextDB.Disconnected
                                  orderby x.Fe_Salida descending
                                  select x).AsEnumerable().Take(50);
                var _discoUserX = (from x in _discoUser
                                   select new { UserName = x.Fe_Salida.ToString("yyyy-MM-dd HH:mm:ss") + " - " + x.UserID.ToString() }).ToList();


                Clients.All.updateUsers(ConnectedClients.Count(), ConnectedClients.Select(x => x.UserName), _discoUserX.Select(x => x.UserName));
            }
        }