/** * Filters the categories and only returns those that are not already assigned to the menu * that is passed in. * */ public static IList<item> filterListByItem(menu_category menu_category,touch_for_foodEntities db) { List<item> filteredList = new List<item>(); MenuItemIM im = new MenuItemIM(db); int resto_id = menu_category.menu.resto_id; bool reject = false; foreach (item i in db.items.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_item> usages = db.menu_item.Where(mi => mi.item_id == i.id && mi.menu_category.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; } if (menu_category.category.id == i.category_id) { foreach (menu_item m_i in im.find(false, menu_category.id)) { if (i.id == m_i.item_id) { reject = true; break; } } if (!reject) { filteredList.Add(i); } } } db.Dispose(); return filteredList; }
public ViewResult PopularItemsByRating(menu menu) { UserIM uim = new UserIM(db); TableIM im = new TableIM(db); ReportsIM rim = new ReportsIM(db); MenuItemIM miIM = new MenuItemIM(db); user authUser = Util.User.UserUtil.getAuthenticatedUser(Request); if (authUser == null) { return View("LogOn", "User"); } user dbUser = uim.find(authUser.id); int t_id = (int)dbUser.current_table_id; restaurant r = db.tables.Find(t_id).restaurant; IEnumerable<MostPopularDishViewModel> mostPopular = rim.findMostPopularCustomer(r); List<KeyValuePair<TouchForFood.Models.menu_item, double>> list = new List<KeyValuePair<TouchForFood.Models.menu_item, double>>(); foreach(var dish in mostPopular){ menu_item mi = miIM.find(dish.menuItemId); list.Add(new KeyValuePair<menu_item,double>(mi,ItemUtil.getAverageRating(mi))); } list.Sort((firstPair, nextPair) => { return nextPair.Value.CompareTo(firstPair.Value); } ); ViewBag.Suggest = "Items are ranked according to rating."; return View("SuggestedByRating", list); }
// // GET: /Menu_Item/ public Menu_ItemController() { im = new MenuItemIM(db); om = new MenuItemOM(db); }
public ViewResult PopularItems() { UserIM uim = new UserIM(db); TableIM im = new TableIM(db); ReportsIM rim = new ReportsIM(db); MenuItemIM miIM = new MenuItemIM(db); user authUser = Util.User.UserUtil.getAuthenticatedUser(Request); if (authUser == null) { return View("LogOn", "User"); } user dbUser = uim.find(authUser.id); int t_id = (int)dbUser.current_table_id; restaurant r = db.tables.Find(t_id).restaurant; IEnumerable<MostPopularDishViewModel> mostPopular = rim.findMostPopularCustomer(r); List<KeyValuePair<TouchForFood.Models.menu_item, int>> list = new List<KeyValuePair<TouchForFood.Models.menu_item, int>>(); foreach(var dish in mostPopular){ menu_item mi = miIM.find(dish.menuItemId); list.Add(new KeyValuePair<menu_item,int>(mi,dish.timesOrdered)); } ViewBag.Suggest = "Items are ranked according to the number of times they have been ordered."; return View("SuggestedItems", list); }