public async Task <int> AddIngredientToMenuItem(AddIngredientToItemModel model) { try { using (SqlConnection db = new SqlConnection(connectionString)) { await db.OpenAsync(); string qry = "INSERT INTO IngredientToItem ([MenuItem],[MenuIngredient]) " + "VALUES (" + "@ItemId,@IngredientId); SELECT CAST(SCOPE_IDENTITY() as int)"; var result = await db.QueryAsync <int>(qry, model); return(result.Single()); } } catch (Exception ex) { Trace.WriteLine("AddIngredientToMenuItem exception " + ex.Message); } return(-1); }
public async Task <int> DeleteIngredientToMenuItem(AddIngredientToItemModel model) { try { using (SqlConnection db = new SqlConnection(connectionString)) { await db.OpenAsync(); string qry = "DELETE FROM IngredientToItem WHERE [MenuItem]=@ItemId AND [MenuIngredient]=@IngredientId"; await db.QueryAsync <int>(qry, model); return(1); } } catch (Exception ex) { Trace.WriteLine("DeleteIngredientToMenuItem exception " + ex.Message); } return(0); }