public IActionResult AddItem(AddMenuItemViewModel addMenuItemVM)
 {
     if (ModelState.IsValid)
     {
         var cheeseID = addMenuItemVM.cheeseID;
         var menuID   = addMenuItemVM.menuID;
         IList <CheeseMenu> existingItems = context.CheeseMenus
                                            .Where(cm => cm.CheeseID == cheeseID)
                                            .Where(cm => cm.MenuID == menuID).ToList();
         if (existingItems.Count == 0)
         {
             CheeseMenu newCheese = new CheeseMenu
             {
                 CheeseID = addMenuItemVM.cheeseID,
                 MenuID   = addMenuItemVM.menuID,
                 Menu     = context.Menus.Single(m => m.ID == addMenuItemVM.menuID),
                 Cheese   = context.Cheeses.Single(c => c.ID == addMenuItemVM.cheeseID)
             };
             context.Add(newCheese);
             context.SaveChanges();
         }
         else
         {
             return(View(addMenuItemVM));
         }
     }
     return(Redirect("/Menu/ViewMenu/" + addMenuItemVM.menuID));
 }
Exemple #2
0
        public IActionResult AddItem(AddMenuItemViewModel addMenuItemViewModel)
        {
            if (ModelState.IsValid)
            {
                var cheeseID = addMenuItemViewModel.CheeseID;
                var menuID   = addMenuItemViewModel.MenuID;

                IList <CheeseMenu> existingitems =
                    context.CheeseMenus.
                    Where(cm => cm.CheeseID == cheeseID).
                    Where(cm => cm.MenuID == menuID).ToList();

                if (existingitems.Count == 0)
                {
                    CheeseMenu menuItem = new CheeseMenu
                    {
                        CheeseID = cheeseID,
                        MenuID   = menuID
                    };

                    context.Add(menuItem);
                    context.SaveChanges();
                }
                return(RedirectToAction("ViewMenu", new { id = menuID }));
            }

            return(View(addMenuItemViewModel));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("ID,Name")] CheeseCategory cheeseCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cheeseCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cheeseCategory));
        }
Exemple #4
0
        public IActionResult Add(AddCategoryViewModel addCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                CheeseCategory newCategory = new CheeseCategory
                {
                    ID   = addCategoryViewModel.ID,
                    Name = addCategoryViewModel.Name
                };
                context.Add(newCategory);
                context.SaveChanges();

                return(Redirect("/Category"));
            }
            return(View(addCategoryViewModel));
        }
Exemple #5
0
 public IActionResult AddCheese(AddCheeseViewModel addch)
 {
     if (ModelState.IsValid)
     {
         //transfer viewmodel's data (from view) to cheese type
         Cheese newaddedcheese = new Cheese()
         {
             Name        = addch.Name,
             Type        = addch.Type,
             Description = addch.Description
         };
         //save new added data in data base
         _context.Add(newaddedcheese);
         _context.SaveChanges();
         return(RedirectToAction("Index", "Cheese"));
     }
     return(View(addch));
 }