Ejemplo n.º 1
0
 public void Post([FromBody] MenuItem prod)
 {
     if (ModelState.IsValid)
     {
         productRepository.Add(prod);
     }
 }
        public void Arrange()
        {
            _repo = new MenuItemRepository();
            _meal = new MenuItem();
            //now that we've initialized our classes, lets populate the repo
            _meal = new MenuItem(1, "Cheeseburger", "A quarter lb of beef on bun with a thick slice of cheese", 5.99f, new List <string>()
            {
                "bun", "burger", "cheese"
            });
            _repo.Add(_meal);

            _meal = new MenuItem(2, "Mac and Cheese", "Huge bowl of al dente macoroni smothered in the yellowest cheesiest sauce you've ever had", 7.49f, new List <string>()
            {
                "macaroni", "butter", "cheese"
            });
            _repo.Add(_meal);

            //we've added two menuItems to the repo
        }//end of method Arrange
        public void AddToRepo_And_ReturnMenuItem_ShouldGetAreEqual()
        {
            _meal = new MenuItem(3, "Chili Cheese Fries", "A plate of our award winning fries, covered in our homemade chili and topped with cheese, sourcream, whatever you like", 9.99f, new List <string>()
            {
                "fries", "chili", "cheese"
            });
            _repo.Add(_meal);

            MenuItem newItem = _repo.ReturnMenuItem(3);

            Assert.AreEqual(_meal, newItem);
        }//end of addToRepo method
        public ActionResult CreateMenuItem(string id, NewMenuItemViewModel model)
        {
            var context            = new AppSecurityContext();
            var menuItemRepository = new MenuItemRepository(context);

            try
            {
                var menuItem = mapper.Map <AppMenuItem>(model);
                menuItemRepository.Add(menuItem);
                context.SaveChanges();
                return(RedirectToAction("menuItems", new { id = model.MenuKey }));
            }
            catch (Exception ex) {
                ViewBag.Error = ex.Message;
            }

            model.AvailablePermissions = PopulatePermissions(model.PermissionId);
            model.AvailableMenuItems   = PopulateMenuItems(model.ParentId);
            return(View(model));
        }