public List <Recepy> GetRecepies() { #if FAKE_DATA return(new List <Recepy>() { new Recepy() { name = "Apple Pie", description = "Desc Apple" }, new Recepy() { name = "Pear Pie", description = "Desc Pear" } }); #endif if (connection == null) { return(null); } SQLiteCommand command = new SQLiteCommand(QUERY_GET_RECEPIES, connection); SQLiteDataReader reader = command.ExecuteReader(); List <Recepy> recepies = new List <Recepy>(); while (reader.Read()) { Recepy recepy = new Recepy(); recepy.description = (string)reader["Description"]; recepy.id = (int)reader["Id"]; recepy.name = (string)reader["Name"]; recepy.ingredients = GetIngredientsInRecepy(recepy.id); recepies.Add(recepy); } return(recepies); }
public void AddRecepy(Recepy recepy) { if (connection == null) { return; } string query = string.Format(QUERY_ADD_RECEPY, recepy.name, recepy.description); SQLiteCommand command = new SQLiteCommand(query, connection); command.ExecuteNonQuery(); }
private void OnOkButtonClicked(object sender, RoutedEventArgs e) { Recepy recepy = new Recepy(); recepy.description = recepyDescriptionTextBox.Text; recepy.name = recepyNameTextBox.Text; foreach (var ingredient in ingredients) { Ingredient i = backendFacilities.GetIngredient(ingredient.name); IngredientInRecepy iir = new IngredientInRecepy(); iir.amount = ingredient.amount; iir.ingredientId = i != null ? i.id : -1; iir.unit = ingredient.unit; recepy.ingredients.Add(iir); } backendFacilities.AddRecepy(recepy); }
public Recepy GetRecepy(int id) { if (connection == null) { return(null); } string query = string.Format(QUERY_GET_RECEPY, id.ToString(), "Id"); SQLiteCommand command = new SQLiteCommand(query, connection); SQLiteDataReader reader = command.ExecuteReader(); Recepy recepy = null; while (reader.Read()) { recepy = new Recepy(); recepy.description = (string)reader["Description"]; recepy.id = (int)reader["Id"]; recepy.name = (string)reader["Name"]; recepy.ingredients = GetIngredientsInRecepy(id); } return(recepy); }