private static void PrintRecipe(string name) { using (var context = new RecipeCatalogContext()) { var Recipes = context.Recipe .Where(x => x.RecipeTitle == name) .OrderBy(f => f.RecipeId); foreach (var x in Recipes) { int index = x.RecipeId; var Products = context.Product .Where(f => f.FkrecipeId == index); Console.WriteLine("**{0}**", x.RecipeTitle); Console.WriteLine("Порции: {0}", x.RecipePortions); Console.WriteLine("Нужно време: {0} минути", x.RecipeTime); Console.WriteLine(); Console.WriteLine("**Нужни продукти**"); foreach (var p in Products) { Console.Write("{0}", p.ProductTitle); Console.Write(" {0}", p.ProductAmount); Console.Write(" {0}", p.ProductAmontType); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("**Начин на приготвяне**"); Console.WriteLine("{0}", x.RecipeInstruction); } } }
private static void SaveRecipe(string title, string instruction, int time, int portion, int timer, List <string> listName, List <double> listAmount, List <string> listAmountType) { using (var context = new RecipeCatalogContext()) { var r = new Recipe(); r.RecipeTitle = title; r.RecipeTime = time; r.RecipePortions = portion; r.RecipeInstruction = instruction; for (int i = 0; i < timer; i++) { var p = new Product(); p.ProductTitle = listName[i]; p.ProductAmount = listAmount[i]; p.ProductAmontType = listAmountType[i]; r.Product.Add(p); } context.Recipe.Add(r); context.SaveChanges(); Console.WriteLine(); Console.WriteLine("Промените бяха запазени!"); } }
private static void PrintAllRecipes() { using (var context = new RecipeCatalogContext()) { var Recipes = context.Recipe.OrderBy(x => x.RecipeId); foreach (var x in Recipes) { Console.WriteLine("-->{0}", x.RecipeTitle); } } }
private static bool RecipeExist(string name) { var context = new RecipeCatalogContext(); var recipes = context.Recipe; bool n = false; foreach (var x in recipes) { if (x.RecipeTitle == name) { n = true; } } return(n); }
private static void DeleteRecipe(string name) { var context = new RecipeCatalogContext(); var recipes = context.Recipe.Where(x => x.RecipeTitle == name); foreach (var x in recipes) { int index = x.RecipeId; var products = context.Product.Where(x => x.FkrecipeId == index); foreach (var p in products) { context.Product.Remove(p); } context.Recipe.Remove(x); } context.SaveChanges(); Console.WriteLine("Успешно изтрихте рецепта: {0}", name); }
private static void UpdateProducts(string name) { Console.Write("Името на продукта, който искате да промените:"); var OldProduct = Console.ReadLine(); Console.Write("Ново име:"); var NewProductName = Console.ReadLine(); Console.Write("Ново количество:"); double NewProductAmount = 0; while (true) { try { NewProductAmount = double.Parse(Console.ReadLine()); break; } catch { Console.WriteLine("Въведената стойност трябва да е число!"); } } Console.Write("Нова мерна единица:"); var NewProductAmountType = Console.ReadLine(); var context = new RecipeCatalogContext(); var recipes = context.Recipe.Where(x => x.RecipeTitle == name); foreach (var x in recipes) { var products = context.Product.Where(p => p.FkrecipeId == x.RecipeId) .Where(y => y.ProductTitle == OldProduct); foreach (var y in products) { y.ProductTitle = NewProductName; y.ProductAmount = NewProductAmount; y.ProductAmontType = NewProductAmountType; } context.SaveChanges(); } Console.WriteLine(); Console.WriteLine("Продукта бе запаметен!"); System.Threading.Thread.Sleep(5000); FindRecipe(name); }
private static void UpdateRecipe(string name) { while (true) { Console.WriteLine("Какво искате да промените:"); Console.WriteLine("-->Порции"); Console.WriteLine("-->Време"); Console.WriteLine("-->Иструкции"); Console.WriteLine("-->Продукти"); Console.WriteLine("-->Нищо"); while (true) { var Input1 = Console.ReadLine().ToLower(); if (Input1 == "порции") { Console.Write("Въведете нова стойност:"); var NewPortion = 0; while (true) { try { NewPortion = int.Parse(Console.ReadLine()); break; } catch { Console.WriteLine("Въведената стойност трябва да е цяло число!"); } } var context = new RecipeCatalogContext(); var recipes = context.Recipe.Where(x => x.RecipeTitle == name); foreach (var r in recipes) { r.RecipePortions = NewPortion; } context.SaveChanges(); Console.WriteLine("Успешно променихте стойността!"); System.Threading.Thread.Sleep(5000); Console.Clear(); FindRecipe(name); break; } else if (Input1 == "време") { Console.Write("Въведете нова стойност:"); var NewTime = 0; while (true) { try { NewTime = int.Parse(Console.ReadLine()); break; } catch { Console.WriteLine("Въведената стойност трябва да е цяло число!"); } } var context = new RecipeCatalogContext(); var recipes = context.Recipe.Where(x => x.RecipeTitle == name); foreach (var r in recipes) { r.RecipeTime = NewTime; } context.SaveChanges(); Console.WriteLine("Успешно променихте стойността!"); System.Threading.Thread.Sleep(5000); Console.Clear(); FindRecipe(name); break; } else if (Input1 == "инструкции") { Console.Write("Въведете нова стойност:"); var NewInstruction = Console.ReadLine(); var context = new RecipeCatalogContext(); var recipes = context.Recipe.Where(x => x.RecipeTitle == name); foreach (var r in recipes) { r.RecipeInstruction = NewInstruction; } context.SaveChanges(); Console.WriteLine("Успешно променихте стойността!"); System.Threading.Thread.Sleep(5000); Console.Clear(); FindRecipe(name); break; } else if (Input1 == "продукти") { Console.WriteLine(); UpdateProducts(name); } else if (Input1 == "нищо") { System.Threading.Thread.Sleep(5000); Console.Clear(); FindRecipe(name); break; } else { Console.WriteLine("Невалидна команда!"); } } break; } }