Beispiel #1
0
        public void CreateOrJoin(string key, string email)
        {
            var group = _groups.FirstOrDefault(g => g.Key == key);

            if (group == null)
            {
                group = new DrinkingGroup {
                    Key = key, Owner = Context.ConnectionId
                };
                _groups.Add(group);
            }

            if (group.HasFinished || group.HasStarted)
            {
                throw new Exception("You cannot join a group which has started or finished");
            }

            Random rnd = new Random();

            group.Glasses.Add(new Glass {
                ConnectionId = Context.ConnectionId, Email = email, Drink = rnd.Next(1, 7)
            });

            BroadcastGroup(group);
        }
        private void BroadcastGroup(DrinkingGroup group, bool removing = false)
        {
            var clients = group.Glasses.Select(g => g.ConnectionId).ToList();

            Clients.Clients(clients).SendAsync("Group", removing ? null : group);
        }