//When you delete a category all the food items inside will be deleted as well public static void DeleteFoodItemsInsideCategory(FoodLists FoodLists, int deleteNum, MenuEntry item) { if (FoodLists.CategoryList[deleteNum] == item.Categories) { FoodLists.FoodItemList.Remove(item); } }
public IActionResult MenuFoodEntry(string id = "") { ViewData["tableNum"] = id; FoodLists.FoodItemList.Clear(); FoodLists.CategoryList.Clear(); //When existing user logs in, the menu information will be retrieved var containsUser = _context.MenuEntry.Where(x => x.UserName == User.Identity.Name); //adds food items to two lists FoodLists = Helper.AddCategoryandFoodItems(containsUser, FoodLists); //deletes any duplicate categories and adds the new list with no repeating categories List <string> distinctCategory = FoodLists.CategoryList.Distinct().ToList(); FoodLists.CategoryList.Clear(); FoodLists.CategoryList.AddRange(distinctCategory); return(View(FoodLists)); }
//******************************************* Home Controller ******************************************************************************* //Menu food items will be retrieved from database if user login is recognized ( MenuFoodEntry - HttpGet ) public static FoodLists AddCategoryandFoodItems(IQueryable <MenuEntry> containsUser, FoodLists FoodLists) { foreach (var item in containsUser) { FoodLists.CategoryList.Add(item.Categories); FoodLists.FoodItemList.Add(new MenuEntry() { UserName = item.UserName, Tables = item.Tables, Categories = item.Categories, Items = item.Items, Prices = item.Prices }); } return(FoodLists); }