Esempio n. 1
0
        /// <summary>
        /// When deleteing a menu category set it's is_deleted to true,as well as cascade to menu items.
        /// only allow this if the menu category is not active
        /// </summary>
        /// <param name="menu_cat">menu category to delete</param>
        /// <returns>number of rows affected</returns>
        /// <exception cref="ItemActiveException">Item is currently set to active</exception>
        /// <exception cref="InvalidOperationException"></exception>
        public override int delete(int id)
        {
            menu_category menu_cat = db.menu_category.Find(id);
            int result = 0;
            MenuItemOM om = new MenuItemOM(db);
            if (!menu_cat.is_active)
            {
                menu_cat.is_deleted = true;

                IList<menu_item> menu_item_list = menu_cat.menu_item.ToList();
                for (int i = 0; i < menu_item_list.Count; i++)
                {
                    menu_item mi = menu_item_list.ElementAt(i);
                    mi.is_active = false;
                    om.delete(mi.id);
                }
                db.Entry(menu_cat).State = EntityState.Modified;
                result = db.SaveChanges();

                //Calling edit will update the version
                edit(menu_cat);

            }
            else
            {
                throw new ItemActiveException("This category is currently active! Cannot delete it.");
            }
            return result;
        }
Esempio n. 2
0
        public void DeleteItemActiveExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            MenuItemOM target = new MenuItemOM(db);
            menuItem1.is_active = true;
            db.Entry(menuItem1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            int actual = target.delete(menuItem1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.IsNotNull(db.order_item.Find(orderItem1.id));
        }
Esempio n. 3
0
        public int RemoveMenuItem(int id)
        {
            int result = 0;
            MenuItemOM om = new MenuItemOM(db);

            try
            {
                result = om.delete(id);
            }
            catch (Exceptions.ItemActiveException e)
            {
                ViewBag.error = e.Message;
            }

            return result;
        }
Esempio n. 4
0
        public void DeleteTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            MenuItemOM target = new MenuItemOM(db);
            int expected = 1;
            int version = menuItem1.version;
            //Check-Setup
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.IsNotNull(db.order_item.Find(orderItem1.id));

            //Act
            int actual = target.delete(menuItem1.id);

            //Assert
            db = new touch_for_foodEntities();
            menu_item mi = db.menu_item.Find(menuItem1.id);
            Assert.IsTrue(mi.is_deleted);
            Assert.AreEqual(mi.version, ++version);
            Assert.AreEqual(expected, actual);
        }