public/Save-Recipe.ps1
|
function Save-Recipe { [CmdletBinding()] param( [int]$RecipeId = 0, [Parameter(Mandatory)][string]$Title, [string]$Description = "", [string]$Notes = "", [string]$Source = "", [int]$PrepTimeMin = 0, [int]$CookTimeMin = 0, [int]$Servings = 0 ) $titleSafe = ConvertTo-SqlSafe $Title $descSafe = ConvertTo-SqlSafe $Description $notesSafe = ConvertTo-SqlSafe $Notes $srcSafe = ConvertTo-SqlSafe $Source if ($RecipeId -le 0) { $result = Invoke-RecipeDbQuery -Query @" INSERT INTO Recipes (Title, Description, Notes, PrepTimeMin, CookTimeMin, Servings, Source) VALUES ('$titleSafe', '$descSafe', '$notesSafe', $PrepTimeMin, $CookTimeMin, $Servings, '$srcSafe'); SELECT last_insert_rowid() AS RecipeId; "@ return [int]$result.RecipeId } Invoke-RecipeDbQuery -Query @" UPDATE Recipes SET Title='$titleSafe', Description='$descSafe', Notes='$notesSafe', PrepTimeMin=$PrepTimeMin, CookTimeMin=$CookTimeMin, Servings=$Servings, Source='$srcSafe', UpdatedAt=datetime('now') WHERE RecipeId=$RecipeId; "@ | Out-Null $RecipeId } |