public IProductList FindByCategory(IUser currentUser, IProductListInputModel query) { // Find the list of products string url = "ProductService.svc/rest/ListProducts2?"; url += addUserUrlDetails(currentUser); url += "&statusSeed=" + _configuration["Storm:StatusSeed"]; if (query.CategoryIds != null) { url += "&categorySeed=" + string.Join(",", query.CategoryIds); } if (query.FlagIds != null) { url += "&flagSeed=" + string.Join(",", query.FlagIds); } if (!string.IsNullOrEmpty(query.Query)) { url += "&searchString=" + System.Web.HttpUtility.UrlEncode(query.Query); } url += "&pageNo=" + (query.PageNumber > 0 ? query.PageNumber : 1); url += "&pageSize=" + (query.PageSize > 0?query.PageSize:PageSize); url += "&asVariants=1"; var productList = _connectionManager.GetResult <StormProductList>(url); ProductListDto result = new ProductListDto(); result.ProductCount = productList.ItemCount; result.PageSize = PageSize; result.PageNumber = (query.PageNumber > 0 ? query.PageNumber : 1); result.Products = new List <IProduct>(); Dictionary <string, ProductDto> variants = new Dictionary <string, ProductDto>(); foreach (var item in productList.Items) { ProductDto p = (ProductDto)_productBuilder.BuildFromItem(item); if (!string.IsNullOrEmpty(p.GroupByKey)) { if (variants.ContainsKey(p.GroupByKey)) { variants[p.GroupByKey].Variants.Add((VariantDto)p.PrimaryVariant); } else { variants[p.GroupByKey] = p; result.Products.Add(p); } } else { result.Products.Add(p); } } return(result); }