public IActionResult AddMeal(AddMealViewModel addMealViewModel, int id) { if (ModelState.IsValid) { //var StudentID = addMealViewModel.StudentID; Student student = context.Students.Single(s => s.ID == id); FoodAmount newFoodAmount = context.FoodAmounts.Single(f => f.ID == addMealViewModel.FoodAmountID); MealTime newMealTime = context.MealTimes.Single(m => m.ID == addMealViewModel.MealTimeID); MealDescription newMealDescription = new MealDescription { StudentID = student.ID, Description = addMealViewModel.Description, MealTime = newMealTime, FoodAmount = newFoodAmount }; context.MealDescriptions.Add(newMealDescription); context.SaveChanges(); return(Redirect(string.Format("/Form/ToddlerForm/{0}", student.ID))); } return(View(addMealViewModel)); }
//"overloaed" constructor public Menu(int number, string name, MealDescription description, VegetableSide vegetable, SecondSide side_second, bool hasSoda, double price) { Number = number; Name = name; DescriptionOfMeal = description; SideOfVegetable = vegetable; Side_Second = side_second; HasSoda = hasSoda; Price = price; }
public OrderMenuViewModel GetOrderMenu() { SqlDataReader reader = this.ExecuteReader( @"SELECT mt.Name AS MealType, m.Id as MealId, m.Name AS MealName FROM Meals AS m JOIN MealTypes AS mt ON m.MealTypeId = mt.Id"); ICollection <MealDescription> appetizers = new List <MealDescription>(); ICollection <MealDescription> mainCourses = new List <MealDescription>(); ICollection <MealDescription> desserts = new List <MealDescription>(); using (reader) { while (reader.Read()) { string mealTypeName = reader.GetString(0); int mealId = reader.GetInt32(1); string mealName = reader.GetString(2); MealDescription meal = new MealDescription(mealId, mealName); switch (mealTypeName) { case "Предястие": appetizers.Add(meal); break; case "Основно ястие": mainCourses.Add(meal); break; case "Десерт": desserts.Add(meal); break; default: throw new InvalidOperationException("No such meal type: " + mealTypeName); } } } OrderMenuViewModel menu = new OrderMenuViewModel(appetizers, mainCourses, desserts); return(menu); }
public MenuViewModel GetMenu() { var reader = this.ExecuteReader( @"select mt.Name as MealType, m.Id as MealId, m.Name as MealName from Meals as m join MealTypes as mt on m.MealTypeId = mt.Id"); var appetizers = new List <MealDescription>(); var mainCourses = new List <MealDescription>(); var desserts = new List <MealDescription>(); using (reader) { while (reader.Read()) { string mealTypeName = reader.GetString(0); int mealId = reader.GetInt32(1); string mealName = reader.GetString(2); var meal = new MealDescription(mealId, mealName); switch (mealTypeName) { case "Предястие": appetizers.Add(meal); break; case "Основно ястие": mainCourses.Add(meal); break; case "Десерт": desserts.Add(meal); break; default: throw new InvalidOperationException("No such meal type: " + mealTypeName); } } } MenuViewModel menu = new MenuViewModel(appetizers, mainCourses, desserts); return(menu); }
private void AddMeal() { Menu newMenu = new Menu(); Console.WriteLine("Enter the Meal Number:"); string numberStr = Console.ReadLine(); int number = int.Parse(numberStr); newMenu.Number = number; Console.WriteLine("Enter the Name of the Meal item:"); string name = Console.ReadLine(); newMenu.Name = name; Console.WriteLine("Enter the corresponding number for the Meal Description:\n" + "1. Sandwich\n" + "2. Salad\n" + "3. Dinner"); string DInput = Console.ReadLine(); int DescInput = int.Parse(DInput); MealDescription description = new MealDescription(); //first one is enum name switch (DescInput) { case 1: description = MealDescription.Sandwich; break; case 2: description = MealDescription.Salad; break; case 3: description = MealDescription.Dinner; break; default: Console.WriteLine("Please enter an appropriate number."); break; } newMenu.DescriptionOfMeal = description; Console.WriteLine("Enter the corresponding number for the Vegetable Side:\n" + "1. Corn\n" + "2. Beans\n" + "3. Brocooli"); string VInput = Console.ReadLine(); int VegInput = int.Parse(VInput); VegetableSide vegetable = new VegetableSide(); //first one is enum name switch (VegInput) { case 1: vegetable = VegetableSide.Corn; break; case 2: vegetable = VegetableSide.Beans; break; case 3: vegetable = VegetableSide.Broccoli; break; default: Console.WriteLine("Please enter an appropriate number."); break; } newMenu.SideOfVegetable = vegetable; Console.WriteLine("Enter the corresponding number for the Second Side:\n" + "1. Slaw\n" + "2. Bread\n" + "3. Fries"); string SInput = Console.ReadLine(); int SSInput = int.Parse(SInput); SecondSide side_second = new SecondSide(); //first one is enum name switch (SSInput) { case 1: side_second = SecondSide.Slaw; break; case 2: side_second = SecondSide.Bread; break; case 3: side_second = SecondSide.Fries; break; default: Console.WriteLine("Please enter an appropriate number."); break; } newMenu.Side_Second = side_second; Console.WriteLine("Does the meal include a Soda?Y/N:"); string hasSodaStr = Console.ReadLine().ToLower(); bool hasSoda; if (hasSodaStr.Contains("y")) { hasSoda = true; } else { hasSoda = false; } newMenu.HasSoda = hasSoda; Console.WriteLine("Enter the Price of the Meal item:"); string priceStr = Console.ReadLine(); double price = double.Parse(priceStr); newMenu.Price = price; _menuRepo.AddMealToList(newMenu); }