Exemplo n.º 1
0
        public async Task <IActionResult> GetAllCategories()
        {
            ProductCategoryListViewModel result = await _queryDispatcher.DispatchAsync <QueryProductCategoryListView, ProductCategoryListViewModel>(
                new QueryProductCategoryListView());

            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAllProducts([FromQuery] bool?includeNotForSale)
        {
            if (!includeNotForSale.HasValue)
            {
                includeNotForSale = false;
            }

            ProductListViewModel result = await _queryDispatcher.DispatchAsync <QueryProductListView, ProductListViewModel>(
                new QueryProductListView(includeNotForSale.Value));

            return(Ok(result));
        }
        public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            IReadOnlyCollection <ProductReadModel> products =
                await _queryDispatcher.DispatchAsync <QueryAllProducts, IReadOnlyCollection <ProductReadModel> >(new QueryAllProducts(), cancellationToken);

            if (products.Count > 0)
            {
                foreach (ProductReadModel product in products)
                {
                    Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}");
                }
            }
            else
            {
                System.Console.WriteLine("No products found.");
            }
        }
        public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            string productId = RequestInput("Enter ID of product to display:", input =>
            {
                if (int.TryParse(input, out int i))
                {
                    return(InputValidationResult.Success);
                }

                return(InputValidationResult.WithErrors("Invalid product ID."));
            });

            Product product = await _queryDispatcher.DispatchAsync <QueryProductById, Product>(new QueryProductById(int.Parse(productId)));

            System.Console.WriteLine($"Product ID: {product.Id}, Product Name: {product.Name}, IsActive: {product.IsActive}");
            System.Console.WriteLine(Environment.NewLine);
        }
Exemplo n.º 5
0
        public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            string productId = RequestInput("Enter ID of product to display:", input =>
            {
                if (Guid.TryParse(input, out Guid i))
                {
                    return(InputValidationResult.Success);
                }

                return(InputValidationResult.WithErrors("Invalid product ID."));
            });

            ProductReadModel product = await _queryDispatcher.DispatchAsync <QueryProductById, ProductReadModel>(new QueryProductById(Guid.Parse(productId)));

            if (product != null)
            {
                System.Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}");
            }
            else
            {
                System.Console.WriteLine($"Product with ID {productId} was not found.");
            }
        }