Esempio n. 1
0
        public ProductionQuery(IBikeStoreRepository bikeStoreRepository)
        {
            Field <ListGraphType <BrandType> >(
                "brands",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "brandId"
            }),
                resolve: context =>
            {
                var brandId = context.GetArgument <int?>("brandId");

                if (brandId.HasValue)
                {
                    return(Task.WhenAll(bikeStoreRepository.GetBrand(brandId.Value)));
                }
                return(bikeStoreRepository.GetBrands());
            });

            Field <ListGraphType <ProductType> >(
                "products",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "page"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "itemsPerPage"
            }),
                resolve: context =>
            {
                var page         = context.GetArgument <int>("page");
                var itemsPerPage = context.GetArgument <int>("itemsPerPage");
                return(bikeStoreRepository.GetProducts(page, itemsPerPage));
            });
        }
        public async Task <IActionResult> Brand(int brandId)
        {
            try
            {
                var brand = await _bikeStoreRepository.GetBrand(brandId);

                if (brand == null)
                {
                    return(NotFound());
                }

                return(Ok(brand));
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, ex.Message);
                return(new StatusCodeResult(Status500InternalServerError));
            }
        }