public void PlaceUserOnFreeSeat(Game game, User user, int gameActionID)
        {
            int      freeSeat = GetFreeSeat(game);
            UserSeat seat     = new UserSeat()
            {
                GameID = game.GameID,
                Seat   = freeSeat,
                UserID = user.UserID
            };

            ctx.UserSeat.InsertOnSubmit(seat);
            ctx.SubmitChanges();

            Console.WriteLine(String.Format("{0} is placed on seat {1}.", user.Name, freeSeat));

            GameAction action = ctx.GameAction.Single(ga => ga.GameActionID == gameActionID);

            action.Data = seat.Seat.ToString();

            action.IsCommitted = true;
            ctx.SubmitChanges();
        }
        public void PlaceUserOnFreeSeat(Game game, User user, int gameActionID)
        {
            int freeSeat = GetFreeSeat(game);
            UserSeat seat = new UserSeat()
            {
                GameID = game.GameID,
                Seat = freeSeat,
                UserID = user.UserID
            };
            ctx.UserSeat.InsertOnSubmit(seat);
            ctx.SubmitChanges();

            Console.WriteLine(String.Format("{0} is placed on seat {1}.", user.Name, freeSeat));

            GameAction action = ctx.GameAction.Single(ga => ga.GameActionID == gameActionID);
            action.Data = seat.Seat.ToString();

            action.IsCommitted = true;
            ctx.SubmitChanges();
        }
 partial void DeleteUserSeat(UserSeat instance);
 partial void UpdateUserSeat(UserSeat instance);
 partial void InsertUserSeat(UserSeat instance);
 private void detach_UserSeat(UserSeat entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
 private void attach_UserSeat(UserSeat entity)
 {
     this.SendPropertyChanging();
     entity.User = this;
 }
 partial void DeleteUserSeat(UserSeat instance);
 partial void UpdateUserSeat(UserSeat instance);
 partial void InsertUserSeat(UserSeat instance);
		private void detach_UserSeat(UserSeat entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
		private void attach_UserSeat(UserSeat entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
        public void PayBlinds(Game game)
        {
            // the next round begins!
            game.Round++;
            Console.WriteLine(string.Format("Round {0} begins.", game.Round));

            // advance button position
            int             buttonPosition = game.CurrentButtonPosition;
            List <UserSeat> seats          = ctx.UserSeat.Where(us => us.GameID == game.GameID)
                                             .OrderBy(us => us.Seat)
                                             .ToList();

            // get next occupied seat
            while (!seats.Any(s => s.Seat == buttonPosition))
            {
                buttonPosition++;

                if (buttonPosition > seatCount)
                {
                    buttonPosition = 1;
                }
            }

            Console.WriteLine("Move dealer button, pay blinds.");
            game.CurrentButtonPosition = buttonPosition;

            int dealer     = seats.Single(s => s.Seat == buttonPosition).UserID;
            int smallBlind = -1;
            int bigBlind   = -1;

            if (seats.Count == 2)
            {
                // special heads up rule: dealer pays the small blind
                smallBlind = seats.Single(s => s.Seat == buttonPosition).UserID;
                // the other player pays the big blind
                bigBlind = seats.Single(s => s.UserID != smallBlind).UserID;
            }
            else // get players left of dealer seat
            {
                int cursor = buttonPosition;
                while (smallBlind == -1 || bigBlind == -1)
                {
                    cursor++;
                    if (cursor > seatCount)
                    {
                        cursor = 1;
                    }

                    UserSeat nextOccupiedSeat = seats.SingleOrDefault(s => s.Seat == cursor);
                    if (nextOccupiedSeat != null)
                    {
                        if (smallBlind == -1)
                        {
                            smallBlind = nextOccupiedSeat.UserID;
                        }
                        else
                        {
                            bigBlind = nextOccupiedSeat.UserID;
                        }
                    }
                }
            }

            // insert "blinds" action
            GameAction payBlindsAction = new GameAction()
            {
                ActionTypeID = (int)ActionTypes.Blinds,
                GameID       = game.GameID,
                Timestamp    = DateTime.Now,
                IsCommitted  = true,
                Data         = String.Join("|", new object[] { dealer, smallBlind, bigBlind })
            };

            ctx.GameAction.InsertOnSubmit(payBlindsAction);
            ctx.SubmitChanges(); // submit all (advance game round, button position and playBlindsAction)
        }