Exemple #1
0
        async Task Search(ChangeEventArgs e)
        {
            await Task.Run(async() =>
            {
                Page = 1;

                // Do it with Dapr
                //try
                //  {
                //    var products =
                //      await ProductsDaprClient.SearchProductsAsync("api/products/search-products",
                //        new ProductsDaprClient.SearchProductsCommand { Filter = e.Value.ToString(), PageIndex = Page, PageSize = _pageSize },
                //        new CancellationToken());

                //    _productsModel = new ProductsModel { Products = products.Products.ToList(), TotalOfProducts = products.TotalOfProducts };
                //  }
                //  catch (Exception e)
                //  {
                //  // Todo just for Developers!
                //  _errorMessage = $"Error: {e.Message}";
                //    _productsModel = new ProductsModel(); ;
                //  }

                _queryFilter = e.Value?.ToString() ?? string.Empty;
                // Do it with HTTP classic
                var response = await ProductHttpClientService.GetAsync(ProcessUrl());

                if (response.StatusCode == (int)System.Net.HttpStatusCode.OK)
                {
                    _productsModel = JsonSerializer.Deserialize <ProductsModel>(response.Content, new JsonSerializerOptions {
                        PropertyNameCaseInsensitive = true
                    });
                }
                else
                {
                    _errorMessage  = $"Error: {response.Error}";
                    _productsModel = new ProductsModel();
                }
            });
        }
Exemple #2
0
        protected override async Task OnParametersSetAsync()
        {
            // Do it with Dapr
            //try
            //{
            //  ProductsDaprClient.GetProductsResponse products =
            //    await ProductsDaprClient.GetProductsAsync("api/products",
            //      new ProductsDaprClient.GetProductsCommand { Page = Page, PageSize = _pageSize },
            //      new CancellationToken());

            //  _productsModel = new ProductsModel { Products = products.Products.ToList(), TotalOfProducts = products.TotalOfProducts };
            //}
            //catch (Exception e)
            //{
            //  // Todo just for Developers!
            //  _errorMessage = $"Error: {e.Message}";
            //  _productsModel = new ProductsModel();;
            //}

            // Do it with HTTP classic
            var response = await ProductHttpClientService.GetAsync(ProcessUrl());

            if (response.StatusCode == (int)System.Net.HttpStatusCode.OK)
            {
                _productsModel = JsonSerializer
                                 .Deserialize <ProductsModel>(response.Content,
                                                              new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true
                });
            }
            else
            {
                _errorMessage  = $"Error: {response.Error}";
                _productsModel = new ProductsModel();
            }
        }