예제 #1
0
        public override Task OnConnected()
        {
            string authUserId = Context.QueryString["authUserId"];

            //_connections.Add(token, Context.ConnectionId);

            using (var db = new DatabaseContext())
            {
                var connection = db.ChatConnectionMappings.Find(Context.ConnectionId);
                if (connection == null)
                {
                    if (authUserId != "undefined" || authUserId != "")
                    {
                        ChatConnectionMapping newConnection = new ChatConnectionMapping
                        {
                            UserId       = Convert.ToInt32(authUserId),
                            ConnectionId = Context.ConnectionId
                        };
                        db.ChatConnectionMappings.Add(newConnection);
                    }
                    try
                    {
                        db.SaveChanges();
                    }

                    catch (DbUpdateException ex)
                    {
                        // Do something here
                    }
                }
            }
            return(base.OnConnected());
        }
예제 #2
0
        public override Task OnReconnected()
        {
            string authUserId = Context.QueryString["authUserId"];

            using (var db = new DatabaseContext())
            {
                var connection = db.ChatConnectionMappings.Find(Context.ConnectionId);
                if (connection == null)
                {
                    ChatConnectionMapping newConnection = new ChatConnectionMapping
                    {
                        UserId       = Convert.ToInt32(authUserId),
                        ConnectionId = Context.ConnectionId
                    };
                    db.ChatConnectionMappings.Add(newConnection);
                    db.SaveChanges();
                }
                return(base.OnReconnected());
            }



            return(base.OnReconnected());
        }