Beispiel #1
0
        /// <summary>
        /// When deleteing a menu set it's is_deleted to true,
        /// as well as cascade to the menu category and menu items.
        /// only allow this is the menu is not active
        /// </summary>
        /// <param name="menu">menu to be deleted</param>
        /// <returns>number of rows affected</returns>
        /// <exception cref="ItemActiveException">Item is currently set to active</exception>
        public override int delete(int id)
        {
            menu menu = db.menus.Find(id);
            MenuCategoryOM mcOM = new MenuCategoryOM(db);

            int result = 0;
            if (!menu.is_active)
            {
                menu.is_deleted = true;
                menu.version++;
                IList<menu_category> mcList = menu.menu_category.ToList();
                for (int i = 0; i < mcList.Count; i++)
                {
                    menu_category mc = mcList.ElementAt(i);
                    mc.is_active = false;
                    mcOM.delete(mc.id);
                }

                db.Entry(menu).State = EntityState.Modified;
                result = db.SaveChanges();

            }
            else
            {
                throw new ItemActiveException("This menu is currently active! Cannot delete it.");
            }
            return result;
        }
Beispiel #2
0
        public void DeleteItemActiveExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            MenuCategoryOM target = new MenuCategoryOM(db);
            menuCategory1.is_active = true;
            db.Entry(menuCategory1).State = EntityState.Modified;
            db.SaveChanges();

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

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.menu_category.Find(menuCategory1.id).is_deleted);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.IsNotNull(db.order_item.Find(orderItem1.id));
            Assert.IsFalse(db.sides.Find(side1.id).is_deleted);
        }
Beispiel #3
0
        public Boolean edit(menu menu)
        {
            MenuIM im = new MenuIM(db);
            menu dbVersion = im.find(menu.id);
            if (dbVersion.version == menu.version)
            {
                //Activate / Deactivate the menu means changing the active feild to all menu categories inside it
                //if (dbVersion.is_active != menu.is_active)
                //{
                MenuCategoryOM om = new MenuCategoryOM(db);
                IList<menu_category> menu_category_list = menu.menu_category.ToList();
                for (int i = 0; i < menu_category_list.Count; i++)
                {
                    menu_category mc = menu_category_list.ElementAt(i);
                    mc.is_active = menu.is_active;
                    om.edit(mc);
                }
                // }
                ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
                db.Entry(menu).State = EntityState.Modified;
                menu.version = menu.version + 1;
                db.SaveChanges();
                return true;
            }

            return false;
        }
Beispiel #4
0
 public int RemoveMenuCategory(int id)
 {
     int result = 0;
     MenuCategoryOM om = new MenuCategoryOM(db);
     try
     {
         result = om.delete(id);
     }
     catch (Exceptions.ItemActiveException e)
     {
         ViewBag.error = e.Message;
     }
     return result;
 }
 public Menu_CategoryController()
 {
     im = new MenuCategoryIM(db);
     om = new MenuCategoryOM(db);
 }
Beispiel #6
0
        public void DeleteTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            MenuCategoryOM target = new MenuCategoryOM(db);
            int currentVersion = menuCategory1.version;
            //Check-Setup
            Assert.IsFalse(db.menu_category.Find(menuCategory1.id).is_deleted);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);

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

            //Assert
            db = new touch_for_foodEntities();
            menu_category mc = db.menu_category.Find(menuCategory1.id);
            Assert.IsTrue(mc.is_deleted);
            Assert.AreEqual(mc.version, ++currentVersion);
            Assert.IsTrue(db.menu_item.Find(menuItem1.id).is_deleted);
        }