Beispiel #1
0
 public ActionResult DinnerMenu(MenuVM vm)
 {
     vm = SaveMenu(vm, "Dinner");
     return View(vm);
 }
Beispiel #2
0
        private MenuVM SaveMenu(MenuVM vm, string menuType)
        {
            using (var r = new Repository())
            {
                foreach (var c in r.MenuCategories.Include("MenuItems").Where(c => c.CategoryType == menuType))
                {
                    while (c.MenuItems.Any())
                    {
                        r.MenuItems.Remove(c.MenuItems.First());
                    }

                    r.MenuCategories.Remove(c);
                }

                foreach (var c in vm.Categories)
                {
                    r.MenuCategories.Add(new MenuCategoryEntity()
                    {
                        Sequence = c.Sequence,
                        CategoryType = menuType,
                        Name = c.Name,
                        MenuItems = c.MenuItems.ConvertAll(i => new MenuItemEntity()
                        {
                            Sequence = i.Sequence,
                            Name = i.Name,
                            Description = i.Description,
                            Price = i.Price
                        })
                    });
                }

                r.SaveChanges();
            }
            return vm;
        }
Beispiel #3
0
 public ActionResult SushiMenu(MenuVM vm)
 {
     vm = SaveMenu(vm, "Sushi");
     return View(vm);
 }
Beispiel #4
0
        private MenuVM GetMenuFromStore(string menuType)
        {
            MenuVM vm = new MenuVM();

            using (var r = new Repository())
            {
                vm.Categories = new List<Category>();

                foreach (var c in r.MenuCategories.Include("MenuItems").Where(c => c.CategoryType == menuType))
                {
                    vm.Categories.Add(new Category()
                    {
                        Sequence = c.Sequence,
                        Name = c.Name,
                        MenuItems = c.MenuItems.Select(
                                        i => new MenuItem()
                                        {
                                            Sequence = i.Sequence,
                                            Name = i.Name,
                                            Description = i.Description,
                                            Price = i.Price
                                        }).ToList()
                    });
                }
            }
            return vm;
        }
Beispiel #5
0
 public ActionResult LunchMenu(MenuVM vm)
 {
     vm = SaveMenu(vm, "Lunch");
     return View(vm);
 }