public async Task <User> ConnectUserAsync(User user, string roomId) { var room = _context.Rooms.FirstOrDefault(r => r.Id == roomId); user.Score = 0; var users = _context.Users.Where(u => u.RoomId == room.Id).ToList(); users ??= new List <User>(); if (users.Count == 1) { users.Add(user); room.Users = users; _context.Update(room); await SaveChagesAsync(); StartGameEventArgs args = new StartGameEventArgs(); args.roomId = roomId; OnStartGame(args); return(user); } users.Add(user); room.Users = users; _context.Update(room); await SaveChagesAsync(); return(user); }
protected virtual void OnStartGame(StartGameEventArgs e) { StartGame?.Invoke(this, e); }