Exemplo n.º 1
0
        /// <summary>
        /// Removes the item.
        /// </summary>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="tableName">Name of the table.</param>
        public static void RemoveItem(int itemId, string tableName = "progress")
        {
            // Remove an item from the users list
                        // Can be used to remove recommendations if using the optional parameter
                        using ( SQLiteConnection conn = new SQLiteConnection(Db.TableLocation) )
                            {
                                using ( SQLiteCommand cmd = new SQLiteCommand() )
                                    {
                                        // Connect to database
                                        cmd.Connection = conn;
                                        conn.Open();
                                        SqLiteHelper sh = new SqLiteHelper(cmd);

                                        string sql = "DELETE FROM " + sh.Escape(tableName) +
                                                  " WHERE itemid = @itemId AND userid = @userId;";

                                        // Remove item
                                        sh.Execute(sql,
                                            new[]
                                                {
                                                    new SQLiteParameter("@tableName", tableName),
                                                    new SQLiteParameter("@itemId", itemId),
                                                    new SQLiteParameter("@userId", User.CurrentUserId)
                                                });
                                    }
                            }
        }