예제 #1
0
        public bool addItemToMenu(int menu_cat_id, ItemFilterVM i_filter, decimal price)
        {
            bool isSuccess = false;
            item item = i_filter.items.First();
            menu_category mc = db.menu_category.Find(menu_cat_id);
            menu_item mi = new menu_item();

            //Initialize values
            mi.item_id = item.id;
            mi.menu_category_id = menu_cat_id;
            item.category_id = db.menu_category.Find(menu_cat_id).category_id;
            mi.price = price;
            //Inherit parent active status
            mi.is_active = mc.is_active;

            if (item.name != "" && menu_cat_id != 0)
            {
                db.items.Add(item);
                db.menu_item.Add(mi);
                db.SaveChanges();
                isSuccess = true;
            }

            if (isSuccess)
            {
                HttpContext.Session["message"] = item.name + " successfuly added.";
                // Load search data into memory
                SearchUtil su = new SearchUtil();
                su.ClearAndFill();
            }
            else
            {
                HttpContext.Session["error"] = item.name + " could not be added.";
            }

            return isSuccess;
        }
예제 #2
0
 public PartialViewResult FilterItems(menu_category menu_cat)
 {
     ItemFilterVM iFilter = new ItemFilterVM(menu_cat, ItemUtil.filterListByItem(menu_cat,db));
     return PartialView("_ItemTable", iFilter);
 }
예제 #3
0
        public void addItemToMenuTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Decimal price = new Decimal(9.99);
            bool expected = true;
            ItemFilterVM i_filter = new ItemFilterVM();
            i_filter.menu_cat = menuCategory1;
            i_filter.addItem(item1);

            //Act
            bool actual = target.addItemToMenu(menuCategory1.id, i_filter, price);

            //Assert
            Assert.AreEqual(expected, actual);

            //Cleanup
            db = new touch_for_foodEntities();
            List<menu_item> menuItems = db.menu_category.Find(menuCategory1.id).menu_item.ToList<menu_item>();
            foreach (menu_item m in menuItems)
            {
                testDatabase.RemoveMenuItem(m);
            }
        }
예제 #4
0
 public ActionResult CreatePartial(int cat_id)
 {
     ItemFilterVM iFilter = new ItemFilterVM();
     menu_category c = db.menu_category.Find(cat_id);
     iFilter.menu_cat = c;
     iFilter.addItem(new item());
     return PartialView("_ItemCreate", iFilter);
 }
예제 #5
0
        public void CreatePartialTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            int cat_id = db.menu_category.Where(mc => mc.category_id == item1.category_id).First().id;
            PartialViewResult actual;
            ItemFilterVM iFilter = new ItemFilterVM();

            //Act
            iFilter.menu_cat = db.menu_category.Find(cat_id);
            iFilter.addItem(new item());
            actual = (PartialViewResult)target.CreatePartial(cat_id);

            //Assert
            Assert.AreEqual("_ItemCreate", actual.ViewName);
            Assert.AreEqual(cat_id, ((ItemFilterVM)actual.Model).menu_cat.id);
        }