コード例 #1
0
        async Task LocalFetch()
        {
            await Task.Delay(1000);

            var content = LocalResource.GetContent("product-by-category.json");
            var listProductByCategory = JsonSerializer.Deserialize <ProductByCategory[]>(content, new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            });

            var _categories = new List <CategoryModel> {
                new() { Name = "All" }
            };

            _categories.AddRange(listProductByCategory.Select(_ => new CategoryModel {
                Name = _.Category
            }));

            categories = _categories.ToArray();

            products = listProductByCategory
                       .SelectMany(_ => _.Products
                                   .Select(product => new ProductModel
            {
                Title       = product.Title,
                Summary     = product.Summary,
                Description = product.Description,
                Price       = $"${product.Price:N2}",
                UrlImage    = product.UrlImage,
                Order       = product.Order,
                Category    = _.Category,
                CategoryTag = _.Category.ToUpper(),
            }))
                       .OrderBy(_ => _.Order)
                       .ToArray();
        }