//Returns a list of available assets meeting the criteria of the search public IActionResult Results(string searchSerialNumber, string searchDescription, string searchBrand, string searchItemType) { List <Brand> brands = _context.Brands.ToList(); List <AssetType> assetTypes = _context.AssetTypes.ToList(); List <Asset> assets = _context.Assets.Where(x => x.Available == true).ToList(); //Filter results by searching serial number if (!string.IsNullOrEmpty(searchSerialNumber)) { assets = assets.Where(x => x.SerialNumber.ToLower() == searchSerialNumber.ToLower()).ToList(); } //Filter results by searching description if (!string.IsNullOrEmpty(searchDescription)) { assets = assets.Where(x => x.Description.ToLower().Contains(searchDescription.ToLower())).ToList(); } //Filter results by brand if (!string.IsNullOrEmpty(searchBrand)) { assets = assets.Where(x => x.BrandId.ToString() == searchBrand).ToList(); } //Filter results by item type if (!string.IsNullOrEmpty(searchItemType)) { assets = assets.Where(x => x.ItemTypeId.ToString() == searchItemType).ToList(); } SearchAssetViewModel newSearchAssetViewModel = new SearchAssetViewModel(brands, assetTypes, assets); return(View("Search", newSearchAssetViewModel)); }
//Returns search window public IActionResult Search() { List <Brand> brands = _context.Brands.ToList(); List <AssetType> assetTypes = _context.AssetTypes.ToList(); List <Asset> assets = new List <Asset>(); SearchAssetViewModel searchAssetViewModel = new SearchAssetViewModel(brands, assetTypes, assets); return(View(searchAssetViewModel)); }