コード例 #1
0
ファイル: MenuCategoryOM.cs プロジェクト: pmoda/TFFCode
 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;
 }
コード例 #2
0
ファイル: CategoryUtil.cs プロジェクト: pmoda/TFFCode
        /**
         * Filters the categories and only returns those that are not already assigned to the menu
         * that is passed in.
         * */
        public static IList<category> filterListByMenu(menu menu,touch_for_foodEntities db)
        {
            List<category> filteredList = new List<category>();
            MenuCategoryIM im = new MenuCategoryIM(db);

            CategoryIM cim = new CategoryIM(db);
            int resto_id = menu.resto_id;

            bool reject = false;
            foreach (category cat in cim.find().ToList())
            {
                reject = false;
                //First check that the category does belong to the restaurant
                //Find all usages of the category in question in the current restaurant
                List<menu_category> usages = db.menu_category.Where(mc => mc.category_id == cat.id && mc.menu.resto_id == resto_id).ToList();
                //If it was never used by this restaurant, then the restaurant could not have created it
                // because create automatically adds the created item to the menu
                if (usages.Count == 0)
                {
                    reject = true;
                }

                //Check if the category is being used buy the current menu
                foreach (menu_category menu_cat in im.find(false, menu.id))
                {
                    if (cat.id == menu_cat.category_id)
                    {
                        reject = true;
                        break;
                    }
                }
                if (!reject)
                {
                    filteredList.Add(cat);
                }
            }
            return filteredList;
        }
コード例 #3
0
 public Menu_CategoryController()
 {
     im = new MenuCategoryIM(db);
     om = new MenuCategoryOM(db);
 }