public void Save(Player player, Game game)
        {
            if (player.Id < 0) {
                this.Add (player, game);
                return;
            }
            try {
                int tid = entity.BeginTransaction ();
                this.SaveShallow (player, game);

                // Shopping List Sync
                ShoppingListTable shoppingListTable = new ShoppingListTable (this.entity);
                List<Quantifier<GeneralItem>> shoppingList = shoppingListTable.GetAll (player);
                // Delete removed items
                foreach (Quantifier<GeneralItem> generalItemQuantifier in shoppingList) {
                    if (player.ShoppingList.Find (quantifier => quantifier.Item.Equals (generalItemQuantifier.Item)) == null) {
                        shoppingListTable.Delete (player, generalItemQuantifier.Item);
                    }
                }

                // Update likes and add new likes
                foreach (Quantifier<GeneralItem> itemQuantifier in player.ShoppingList) {
                    Quantifier<GeneralItem> findItem = shoppingList.Find (quantifier => quantifier.Item.Equals (itemQuantifier.Item));
                    if (findItem == null) {
                        shoppingListTable.Add (player, itemQuantifier.Item, itemQuantifier.Quantity);
                    } else {
                        if (findItem.Quantity != itemQuantifier.Quantity)
                            shoppingListTable.Save (player, itemQuantifier.Item, itemQuantifier.Quantity);
                    }
                }

                // Inventory Sync
                InventoryTable inventoryTable = new InventoryTable (this.entity);
                List<Quantifier<SpecificItem>> inventory = inventoryTable.GetAll (player);
                // Delete removed items
                foreach (Quantifier<SpecificItem> itemQuantifier in inventory) {
                    if (player.Inventory.Find (quantifier => quantifier.Item.Equals (itemQuantifier.Item)) == null) {
                        inventoryTable.Delete (player, itemQuantifier.Item);
                    }
                }

                // Update likes and add new likes
                foreach (Quantifier<SpecificItem> itemQuantifier in player.Inventory) {
                    Quantifier<SpecificItem> findItem = inventory.Find (quantifier => quantifier.Item.Equals (itemQuantifier.Item));
                    if (findItem == null) {
                        inventoryTable.Add (player, itemQuantifier.Item, itemQuantifier.Quantity);
                    } else {
                        if (findItem.Quantity != itemQuantifier.Quantity)
                            inventoryTable.Save (player, itemQuantifier.Item, itemQuantifier.Quantity);
                    }
                }
                entity.Commit (tid);
            } catch (MySqlException ex) {
                switch (ex.Number) {
                case 0:
                    throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
                case 1045:
                    throw new DatabaseException ("Invalid username/password, please try again", ex);
                default:
                    throw new DatabaseException (ex.Message, ex);
                }
            }
        }
 public Player Get(int id)
 {
     try {
         Player player = GetShallow (id);
         if (player != null) {
             ShoppingListTable shoppingListTable = new ShoppingListTable (this.entity);
             InventoryTable inventoryTable = new InventoryTable (this.entity);
             player.ShoppingList = shoppingListTable.GetAll (player);
             player.Inventory = inventoryTable.GetAll (player);
         }
         return player;
     } catch (MySqlException ex) {
         switch (ex.Number) {
         case 0:
             throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
         case 1045:
             throw new DatabaseException ("Invalid username/password, please try again", ex);
         default:
             throw new DatabaseException (ex.Message, ex);
         }
     }
 }
 public List<Player> GetAll(Game game)
 {
     try {
         List<Player> players = this.GetAllShallow (game);
         ShoppingListTable shoppingListTable = new ShoppingListTable (this.entity);
         InventoryTable inventoryTable = new InventoryTable (this.entity);
         foreach (Player player in players) {
             player.ShoppingList = shoppingListTable.GetAll (player);
             player.Inventory = inventoryTable.GetAll (player);
         }
         return players;
     } catch (MySqlException ex) {
         switch (ex.Number) {
         case 0:
             throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
         case 1045:
             throw new DatabaseException ("Invalid username/password, please try again", ex);
         default:
             throw new DatabaseException (ex.Message, ex);
         }
     }
 }