public ProductSearchResponse GetAllProducts() { List <Product> products = new List <Product>(); productDataManager = new ProductDataManager(); DataSet ds = productDataManager.GetAllProducts(); ProductSearchResponse response = new ProductSearchResponse(); DataTable dt = new DataTable(); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { Product product = new Product(); product.Id = Convert.ToInt32(dr["Id"]); product.Name = dr["Name"].ToString(); product.Description = dr["Description"].ToString(); product.Price = Convert.ToDecimal(dr["Price"]); product.Status = dr["Status"].ToString(); product.Category = new Category(); product.Category.CategoryName = Convert.ToString(dr["CategoryName"]); if (dr["CategoryId"] != System.DBNull.Value) { product.Category.CategoryId = Convert.ToInt32(dr["CategoryId"]); } products.Add(product); } } // NoOfRows = dt.Rows.Count; response.ProductList = products; response.Count = Convert.ToInt32(ds.Tables[1].Rows[0][0]); return(response); }
public async Task <ProductSearch> GetUpdatedProducts(DateTime utc, int pageNum, int perPage) { await RefreshAuthToken(); string PRODUCT_SEARCH_REQUEST = JsonSerializer.Serialize(new ProductSearchRequest(utc, pageNum, perPage)); HttpContent requestBody = new StringContent(PRODUCT_SEARCH_REQUEST, Encoding.UTF8, APPLICATION_JSON); Http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("JWT", Token); HttpResponseMessage response = await Http.PostAsync(string.Empty, requestBody); string responseBody = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { GetErrorAndThrowException(responseBody, AUTH_TOKEN_ERROR_MESSAGE); } ProductSearchResponse result = JsonSerializer.Deserialize <ProductSearchResponse>(responseBody); if (result == null || result.data == null || result.data.productSearch == null) { GetErrorAndThrowException(responseBody, PRODUCT_SEARCH_ERROR_MESSAGE); } return(result.data.productSearch); }
public ProductSearchResponse Search(ProductSearchRequest request) { var response = new ProductSearchResponse(); response.List = _facade.Search(request.Filter, request.PaginationInfo); return(response); }
public void TestMethod1() { IProductManager manager = ProductFactory.GetProductManager(); int PageIndex = 1; ProductSearchResponse products = manager.GetProducts(PageIndex); Assert.IsTrue(products.Count > 0); }
public async Task <IActionResult> Products(string keyword) { var requestCultureFeature = Request.HttpContext.Features.Get <IRequestCultureFeature>(); CultureInfo culture = requestCultureFeature.RequestCulture.Culture; ProductSearchResponse productSearchResponse = await _productService.SearchAsync(keyword, culture.TwoLetterISOLanguageName); return(View(productSearchResponse)); }
public SearchProduct(ProductSearchResponse responseXml) { if (responseXml.Pages != null) { Pagination = new Pagination(responseXml.Pages); } Products = new List <IProduct>(); if (responseXml.Products?.Product?.Count > 0) { Products = responseXml.Products?.Product?.Select(p => new Product(p)); } }
public async Task <ProductSearchResponse> GetProductsForCustomer(Customer customerToAdd) { customerToAdd = _customerDetailsFormatter.Format(customerToAdd); Customer addedCustomer = await _customerRepo.AddAsync(customerToAdd); ProductSearchValidationResult result = _customerValidator.Validate(addedCustomer); IEnumerable <Product> productResults = await GetProductsForCustomer(result, addedCustomer); Request request = await RecordSearch(result, addedCustomer, productResults); ProductSearchResponse response = new ProductSearchResponse(result, request.UniqueId); return(response); }
public async Task <ProductSearchResponse> ProductSearch(ProductSearchRequest productSearchModel, ViatorSetting setting = null) { var uri = $"service/search/products"; var response = await _httpClient.PostAsync <ProductSearchRequest>(GenerateBaseURL(uri, setting), productSearchModel); if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var result = ProductSearchResponse.FromJson(content); return(result); } else { throw new Exception("Viator API - ProductSearch: Api error response"); } }
public void Inventory_ProductSearchResponse_Data_IsCorrect() { var product1 = new Product(); var product2 = new Product(); var response = new ProductSearchResponse { product = new List <Product> { product1, product2 } }; var result = response.Data; Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(product1)); Assert.IsTrue(result.Contains(product2)); }
public async Task <ProductSearchResponse> SearchProduct(ProductContract prd) { ProductContext dbCon = new ProductContext(); //Automapper performance issue will occur in case of 1000+ mapping. Here it should have no performance issue var result = await dbCon.Products.Where(i => i.Title.Equals(_mapper.Map <Product>(prd).Title)).ToListAsync(); ProductSearchResponse res = new ProductSearchResponse { Success = false }; if (result != null) { res.Success = true; res.Products = _mapper.Map <List <ProductContract> >(result); } return(res); }
public async Task <ProductSearchResponse> SearchAsync(string keyword, string langCode) { ProductSearchResponse productSearchResponse = new ProductSearchResponse(); string indexName = $"products_{langCode}"; ISearchResponse <Product> searchResponse = await _elasticClient.SearchAsync <Product>(x => x .Index(indexName) .Query(q => q.MultiMatch(mp => mp .Query(keyword) .Fields(f => f.Fields(f1 => f1.Name, f2 => f2.Description))) )); if (searchResponse.IsValid && searchResponse.Documents != null) { productSearchResponse.Total = (int)searchResponse.Total; productSearchResponse.Products = searchResponse.Documents; } return(productSearchResponse); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var customer = new Customer(this.Customer); ProductSearchResponse result = await _customerService.GetProductsForCustomer(customer); if (result.ValidationResult != ProductSearchValidationResult.Valid) { string errorMessage = GetErrorMessage(result.ValidationResult); ModelState.AddModelError(Constants.VALIDATION_ERROR_KEY, errorMessage); return(Page()); } // pass the request id to retrieve the request results // ideally would use authentication return(RedirectToPage("./CardResults", new { id = result.ResultsId.ToString() })); }