示例#1
0
        /*
         *
         *
         *
         */
        private async Task <Group> AddToGroup(string groupName)
        {
            var group = await _messageReop.GetMessageGroup(groupName);

            var connection = new Connection(Context.ConnectionId, Context.User.FindFirst(ClaimTypes.Name)?.Value);

            if (group == null)
            {
                group = new Group(groupName);
                _messageReop.AddGroup(group);
            }

            group.Connection.Add(connection);

            if (await _messageReop.SaveAll())
            {
                return(group);
            }

            throw new HubException("Failed to join group");
        }
示例#2
0
        /// <summary>
        /// HubCallerContext gives us access to current user name and connection id
        /// </summary>
        private async Task <Group> AddToGroup(string groupName)
        {
            var group = await _repo.GetMessageGroup(groupName);

            var connection = new Connection(Context.ConnectionId, Context.User.GetUsername(), Context.User.GetUserId());

            if (group == null)
            {
                group = new Group(groupName);
                _repo.AddGroup(group);
            }

            group.Connections.Add(connection);

            if (await _repo.SaveAll())
            {
                return(group);
            }

            throw new HubException("Failed to join group");
        }