Esempio n. 1
0
        public IActionResult Catagory(int id)
        {
            if (id == 0)
            {
                return(Redirect("/Catagory"));
            }

            CheeseCatagory theCatagory = context.Catagories
                                         .Include(cat => cat.Cheeses)
                                         .Single(cat => cat.ID == id);

            ViewBag.title = "Cheeses in catagory: " + theCatagory.Name;

            return(View("Index", theCatagory.Cheeses));
        }
        public IActionResult Add(AddCatagoryViewModel addCatagoryViewModel)
        {
            if (ModelState.IsValid)
            {
                CheeseCatagory newCatagory = new CheeseCatagory
                {
                    Name = addCatagoryViewModel.Name
                };
                context.Catagories.Add(newCatagory);
                context.SaveChanges();

                return(Redirect("/Catagory"));
            }

            return(View(addCatagoryViewModel));
        }
Esempio n. 3
0
        public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                CheeseCatagory newCheeseCatagory = context.Catagories.Single(c => c.ID == addCheeseViewModel.CatagoryID);

                // Add the new cheese to my existing cheeses
                Cheese newCheese = new Cheese
                {
                    Name        = addCheeseViewModel.Name,
                    Description = addCheeseViewModel.Description,
                    Catagory    = newCheeseCatagory
                };

                context.Cheeses.Add(newCheese);
                context.SaveChanges();

                return(Redirect("/Cheese"));
            }

            return(View(addCheeseViewModel));
        }