Exemplo n.º 1
0
        public IActionResult SelectCategory(CategoryViewModel vm)
        {
            CategoryModel            catModel  = new CategoryModel(_db);
            MenuItemModel            menuModel = new MenuItemModel(_db);
            List <MenuItem>          items     = menuModel.GetAllByCategory(vm.CategoryId);
            List <MenuItemViewModel> vms       = new List <MenuItemViewModel>();

            if (items.Count > 0)
            {
                foreach (MenuItem item in items)
                {
                    MenuItemViewModel mvm = new MenuItemViewModel();
                    mvm.Qty          = 0;
                    mvm.CategoryId   = item.CategoryId;
                    mvm.CategoryName = catModel.GetName(item.CategoryId);
                    mvm.Description  = item.Description;
                    mvm.Id           = item.Id;
                    mvm.PRO          = item.Protein;
                    mvm.SALT         = item.Salt;
                    mvm.FAT          = Convert.ToDecimal(item.Fat);
                    mvm.FBR          = item.Fibre;
                    mvm.CHOL         = item.Cholesterol;
                    mvm.CAL          = item.Calories;
                    mvm.CARB         = item.Carbs;
                    vms.Add(mvm);
                }
                MenuItemViewModel[] myMenu = vms.ToArray();
                HttpContext.Session.Set <MenuItemViewModel[]>("menu", myMenu);
            }
            vm.SetCategories(HttpContext.Session.Get <List <Category> >("categories"));
            return(View("Index", vm)); // need the original Index View here
        }