private List <ItemsTagsInfo> FindAnotherUserInventory(int?id) { var inventoryToView = _repo.Inventory.FindByCondition(i => i.InventoryId == id).SingleOrDefault(); var allItems = _repo.Inventory.FindAll().ToList(); List <ItemsTagsInfo> myItemsList = new List <ItemsTagsInfo>(); foreach (Inventory item in allItems) { ItemsTagsInfo itemTagsLocation = new ItemsTagsInfo(); if (item.RoboDexerId == id) { var roboDexerItems = _repo.Items.FindByCondition(i => i.ItemId == item.ItemId).SingleOrDefault(); if (roboDexerItems == null) { continue; } var allInventory = _repo.Inventory.FindByCondition(i => i.ItemId == inventoryToView.ItemId).SingleOrDefault(); itemTagsLocation.Item = roboDexerItems; //itemTagsLocation.Item = roboDexerItems; //itemTagsLocation.TagName = tags.Name; myItemsList.Add(itemTagsLocation); } } return(myItemsList); }
public IActionResult Search(string searchTerm) { NavLayout(); var allTags = _repo.Tags.FindAll(); var allItems = _repo.Items.FindAll(); if (!String.IsNullOrEmpty(searchTerm)) { allItems = allItems.Where(a => a.Name.Contains(searchTerm)); } if (!String.IsNullOrEmpty(searchTerm)) { allTags = allTags.Where(a => a.Name.Contains(searchTerm)); } List <ItemsTagsInfo> listOfAllItems = new List <ItemsTagsInfo>(); //Here I am adding the item, and tag name and tag id into a single ItemTagsInfo object. foreach (Tags tag in allTags) { ItemsTagsInfo itemTagsInfo = new ItemsTagsInfo(); itemTagsInfo.TagName = tag.Name; itemTagsInfo.TagId = tag.TagId; var items = _repo.ItemTags.FindByCondition(i => i.TagsId == tag.TagId).ToList(); foreach (ItemTags item in items) { var foundItem = _repo.Items.FindByCondition(i => i.ItemId == item.ItemId).SingleOrDefault(); itemTagsInfo.Item = foundItem; listOfAllItems.Add(itemTagsInfo); } } return(View(listOfAllItems)); }