public async Task SendMessage(string message)
        {
            int    iUserId    = Convert.ToInt32(Context.User.Claims.FirstOrDefault(x => x.Type == "Id")?.Value);
            string sGroupName = "WebSocket_" + Context.User.Identity.Name + "_" + iUserId;

            Memo entityUserMemo = await RedisMethod.GetUserMemoAsync(sGroupName, -1, () => GetUserMemo(iUserId));

            entityUserMemo.Scontent = message;
            RedisMethod.SetUserMemo(sGroupName, entityUserMemo, -1);
            await Clients.Group(sGroupName).SendAsync("ReceiveMessage", message);

            //await Clients.All.SendAsync("ReceiveMessage", message);
        }
Example #2
0
        public async Task <IActionResult> IndexAsync(int iPageId)
        {
            int iUserId = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type == "Id")?.Value);
            //Memo entityMemo = await _memoService.SelectAsync(new Memo() { iUserId = iUserId });
            string sGroupName     = "WebSocket_" + User.Identity.Name + "_" + iUserId;
            Memo   entityUserMemo = await RedisMethod.GetUserMemoAsync(sGroupName, -1, () => GetUserMemo(iUserId));

            if (entityUserMemo == null)
            {
                entityUserMemo = new Memo()
                {
                    iUserId = iUserId
                };
                await _memoService.AppendAsync(entityUserMemo, User.Identity.Name);
            }
            ViewBag.Scontent = entityUserMemo.Scontent;
            return(Empty(iPageId));
        }