public Task <List <ProductAutoCompleteViewModel> > SearchProductByName(SearchProductByNameCategoryIdSubCategoryId productName) { var shop = _context.Shops.Where(x => x.Id == productName.ShopId).FirstOrDefault(); try { if (shop != null && !string.IsNullOrEmpty(productName.ProductId)) { var result = _context.VendorProducts.FromSqlRaw($"select DISTINCT ProductName,ProductId from VendorProduct.Vendor{shop.tableName}Products where ProductName like '%{productName.ProductId}%' order by ProductName OFFSET 0 ROWS FETCH NEXT 15 rows ONLY;") .Select(x => new ProductAutoCompleteViewModel { ProductId = x.ProductId, ProductName = x.ProductName }).AsQueryable(); return(Task.FromResult(result.ToList())); } else { var result = _context.VendorProducts.FromSqlRaw($"select DISTINCT ProductName,ProductId from VendorProduct.Vendor{shop.tableName}Products order by ProductName OFFSET 0 ROWS FETCH NEXT 5 rows ONLY;") .Select(x => new ProductAutoCompleteViewModel { ProductId = x.ProductId, ProductName = x.ProductName }).AsQueryable(); return(Task.FromResult(result.ToList())); } } catch (Exception ex) { throw; } }
public async Task <ActionResult <IEnumerable <ProductAutoCompleteViewModel> > > GetSearchProductByName(SearchProductByNameCategoryIdSubCategoryId productName) { var result = await _singleton.vendorRepository.SearchProductByName(productName); return(result); }