Пример #1
0
 //
 // GET: /Order/
 public OrderController()
 {
     im = new OrderIM(db);
     om = new OrderOM(db);
     order_itemOM = new Order_ItemOM(db);
     menu_itemOM = new MenuItemOM(db);
 }
Пример #2
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;
        }
Пример #3
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));
        }
Пример #4
0
 //
 // GET: /Menu_Item/
 public Menu_ItemController()
 {
     im = new MenuItemIM(db);
     om = new MenuItemOM(db);
 }
Пример #5
0
 public Boolean edit(menu_category menu_category)
 {
     MenuCategoryIM im = new MenuCategoryIM(db);
     menu_category dbVersion = im.find(menu_category.id);
     if (dbVersion.version == menu_category.version)
     {
         //Activate / Deactivate the menu category means changing the active feild to all menu items inside it
         //if (dbVersion.is_active != menu_category.is_active)
         //{
         MenuItemOM om = new MenuItemOM(db);
         IList<menu_item> menu_item_list = menu_category.menu_item.ToList();
         for (int i = 0; i < menu_item_list.Count; i++)
         {
             menu_item mi = menu_item_list.ElementAt(i);
             mi.is_active = menu_category.is_active;
             om.edit(mi);
         }
         //}
         ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
         db.Entry(menu_category).State = EntityState.Modified;
         menu_category.version = menu_category.version + 1;
         db.SaveChanges();
         return true;
     }
     return false;
 }
Пример #6
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;
        }
Пример #7
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);
        }