public async Task <RecipeDataModel> UpdateRecipe(RecipeDataModel recipe) { Recipes.Update(recipe); await this.SaveChangesAsync(); return(recipe); }
public static void SaveRecipe(RecipeDataModel recipe) { using SQLiteConnection connection = DatabaseUtility.GetNewConnection(); using SQLiteCommand updateRecipeCommand = connection.CreateCommand(); updateRecipeCommand.CommandText = "UPDATE Recipes SET size = @size, boilTime = @boilTime, name = @name, yeastIngredientInfo = @yeastIngredientInfo, beerStyleInfo = (SELECT id FROM Styles WHERE name = @beerStyleName) " + "WHERE id = @id"; updateRecipeCommand.Parameters.AddWithValue("id", recipe.RecipeId); updateRecipeCommand.Parameters.AddWithValue("size", recipe.Size); updateRecipeCommand.Parameters.AddWithValue("boilTime", recipe.BoilTime); updateRecipeCommand.Parameters.AddWithValue("name", recipe.Name); updateRecipeCommand.Parameters.AddWithValue("yeastIngredientInfo", recipe.YeastIngredient != null ? ((YeastIngredientDataModel)recipe.YeastIngredient).YeastIngredientId : 0); updateRecipeCommand.Parameters.AddWithValue("beerStyleName", recipe.Style != null ? recipe.Style.Name : ""); updateRecipeCommand.ExecuteNonQuery(); if (recipe.YeastIngredient != null) { YeastUtility.UpdateYeastIngredient((YeastIngredientDataModel)recipe.YeastIngredient, connection); } foreach (FermentableIngredientDataModel fermentableIngredient in recipe.FermentableIngredients) { FermentableUtility.UpdateFermentableIngredient(fermentableIngredient, connection); } foreach (HopsIngredientDataModel hopsIngredient in recipe.HopsIngredients) { HopsUtility.UpdateHopsIngredient(hopsIngredient, connection); } connection.Close(); }
public FoodItemViewModel(RecipeDataModel recipeModel, Random rng) { RecipeModel = recipeModel; Labels = new List <InfoLabel>(); _rng = rng; GetAllLabels(); }
// Recipes/Random public IActionResult Random() { var setting = applicationDbContext.Settings.FirstOrDefault(); string settingName = "No settings content"; if (setting != null) { settingName = setting.Name; setting.Name = "Horse"; applicationDbContext.Settings.Update(setting); applicationDbContext.SaveChanges(); } else { applicationDbContext.Settings.Add(new SettingsDataModel { Name = "Dennis", Value = "2" }); applicationDbContext.SaveChanges(); } var newRecipe = applicationDbContext.Recipes.FirstOrDefault(); if (newRecipe == null) { newRecipe = new RecipeDataModel() { Name = "Butter Chicken", Ingredients = new List <IngredientDataModel>() { new IngredientDataModel() { Name = "butter", Quantity = 100, Unit = IngredientUnitDataModel.Grams }, new IngredientDataModel() { Name = "Chicken", Quantity = 1000, Unit = IngredientUnitDataModel.Grams }, new IngredientDataModel() { Name = settingName, Quantity = 1000, Unit = IngredientUnitDataModel.TableSpoon } } }; applicationDbContext.Add(newRecipe); applicationDbContext.SaveChanges(); } return(View(applicationDbContext.Recipes.Include(r => r.Ingredients).FirstOrDefault())); }
public async Task <RecipeDataModel> SaveRecipe(RecipeDataModel recipe) { recipe.CreationDate = DateTime.Now; await Recipes.AddAsync(recipe); await this.SaveChangesAsync(); return(recipe); }
private void DeleteRecipe(RecipeDataModel recipe) { RecipeUtility.DeleteRecipe(recipe); // set the current recipe to the previous recipe in the collection int previousRecipeIndex = SavedRecipes.IndexOf(recipe) - 1; CurrentRecipe = previousRecipeIndex == -1 ? SavedRecipes.FirstOrDefault() : SavedRecipes[previousRecipeIndex]; SavedRecipes.Remove(recipe); }
public static RecipeDataModel CreateRecipe() { using var connection = DatabaseUtility.GetNewConnection(); var yeastIngredient = YeastUtility.CreateYeastIngredient(connection); using var insertCommand = connection.CreateCommand(); insertCommand.CommandText = "INSERT INTO Recipes (size, boilTime, name, beerStyleInfo, yeastIngredientInfo, mashProfileInfo) VALUES(0, 0, '', 0, @yeastIngredientInfo, 0)"; insertCommand.Parameters.AddWithValue("yeastIngredientInfo", yeastIngredient.YeastIngredientId); insertCommand.ExecuteNonQuery(); var recipe = new RecipeDataModel(DatabaseUtility.GetLastInsertedRowId(connection)) { YeastIngredient = yeastIngredient }; connection.Close(); return(recipe); }
public static BatchDataModel CreateBatch(RecipeDataModel recipe) { BatchDataModel batch = null; using (SQLiteConnection connection = DatabaseUtility.GetNewConnection()) { DateTime currentDate = DateTime.Now; using (SQLiteCommand insertCommand = connection.CreateCommand()) { insertCommand.CommandText = "INSERT INTO Batches (brewerName, assistantBrewerName, brewingDate, recipeInfo) VALUES ('', '', @brewingDate, @recipeInfo)"; insertCommand.Parameters.AddWithValue("brewingDate", currentDate.ToString()); insertCommand.Parameters.AddWithValue("recipeInfo", recipe.RecipeId); insertCommand.ExecuteNonQuery(); } batch = new BatchDataModel(DatabaseUtility.GetLastInsertedRowId(connection)) { BrewingDate = currentDate, Recipe = recipe }; connection.Close(); } return(batch); }
public static void DeleteRecipe(RecipeDataModel recipe) { using var connection = DatabaseUtility.GetNewConnection(); if (recipe.YeastIngredient != null) { YeastUtility.DeleteYeastIngredient(((YeastIngredientDataModel)recipe.YeastIngredient).YeastIngredientId, connection); } foreach (FermentableIngredientDataModel fermentableIngredient in recipe.FermentableIngredients) { FermentableUtility.DeleteFermentableIngredient(fermentableIngredient.FermentableId, connection); } foreach (HopsIngredientDataModel hopsIngredient in recipe.HopsIngredients) { HopsUtility.DeleteHopsIngredient(hopsIngredient.HopsId, connection); } using var deleteRecipeCommand = connection.CreateCommand(); deleteRecipeCommand.CommandText = "DELETE FROM Recipes WHERE id = @id"; deleteRecipeCommand.Parameters.AddWithValue("id", recipe.RecipeId); deleteRecipeCommand.ExecuteNonQuery(); }
public static IEnumerable <RecipeDataModel> GetSavedRecipes(IList <Style> availableBeerStyles) { using SQLiteConnection connection = DatabaseUtility.GetNewConnection(); using SQLiteCommand getRecipesCommand = connection.CreateCommand(); getRecipesCommand.CommandText = "SELECT Recipes.id, Recipes.size, Recipes.boilTime, Recipes.name, Styles.name FROM Recipes " + "LEFT JOIN Styles ON Styles.id = Recipes.beerStyleInfo"; using SQLiteDataReader reader = getRecipesCommand.ExecuteReader(); while (reader.Read()) { string styleName = reader[4].ToString(); Style recipeStyle = availableBeerStyles.FirstOrDefault(style => style.Name == styleName); int recipeId = reader.GetInt32(0); var recipe = new RecipeDataModel(recipeId) { Size = reader.GetFloat(1), BoilTime = reader.GetInt32(2), Name = reader.GetString(3), Style = recipeStyle, YeastIngredient = YeastUtility.GetYeastIngredientForRecipe(recipeId, connection) }; foreach (var hopsIngredient in HopsUtility.GetHopsIngredientsForRecipe(recipeId, connection)) { hopsIngredient.PropertyChanged += recipe.Ingredient_PropertyChanged; recipe.HopsIngredients.Add(hopsIngredient); } foreach (var fermentableIngredient in FermentableUtility.GetFermentableIngredientsForRecipe(recipeId, connection)) { fermentableIngredient.PropertyChanged += recipe.Ingredient_PropertyChanged; recipe.FermentableIngredients.Add(fermentableIngredient); } yield return(recipe); } connection.Close(); }
public IActionResult Edit(RecipeDataModel recipe) { applicationDbContext.Recipes.Update(recipe); applicationDbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(RecipeDataModel Recipe) { applicationDbContext.Recipes.Add(Recipe); applicationDbContext.SaveChanges(); return(RedirectToAction("Index")); }
private bool CanAddNewBatch(RecipeDataModel recipe) { return(recipe != null); }
private void AddNewBatch(RecipeDataModel recipe) { SaveCurrentBatch(); CurrentBatch = BatchUtility.CreateBatch(recipe); SavedBatches.Add(CurrentBatch); }