Example #1
0
        public void RemoveItem(string item)
        {
            var itemID  = DBFunctions.GetItemID(item);
            var hasItem = DBFunctions.UserHasItem(this, itemID);

            if (!hasItem)
            {
                return;
            }

            using (var con = new SQLiteConnection(Constants.Values.DB_CONNECTION_STRING))
            {
                con.Open();


                var stm = "UPDATE USER_ITEMS SET COUNT = COUNT - 1 WHERE ITEM_ID = @itemid AND USER_ID = @userid";
                using (var com = new SQLiteCommand(stm, con))
                {
                    com.Parameters.AddWithValue("@itemid", itemID);
                    com.Parameters.AddWithValue("@userid", ID);
                    com.ExecuteNonQuery();
                }

                var count = DBFunctions.UserItemCount(this, itemID);
                if (count <= 0)
                {
                    stm = "DELETE FROM USER_ITEMS WHERE ITEM_ID = @itemid AND USER_ID = @userid";
                    using (var com = new SQLiteCommand(stm, con))
                    {
                        com.Parameters.AddWithValue("@itemid", itemID);
                        com.Parameters.AddWithValue("@userid", ID);
                        com.ExecuteNonQuery();
                    }
                }
            }
        }
Example #2
0
 public bool HasItem(int itemID, int amount = 1)
 {
     return(DBFunctions.UserHasItem(this, itemID, amount));
 }