コード例 #1
0
        public async Task <ActionResult <IAsyncEnumerable <ProductDto> > > GetProduct(int supplierId, int productId)
        {
            var query = new GetProductForSupplierByIdQuery
            {
                SupplierId = supplierId,
                ProductId  = productId,
            };
            var result = await mediator.Send(query);

            return(result.Success
                ? (ActionResult <IAsyncEnumerable <ProductDto> >)Ok(ProductDto.FromCoreProductDto(result.Data))
                : BadRequest(result.ErrorMessages));
        }
コード例 #2
0
        public async Task <ActionResult <ProductDto> > UpdateProduct(int supplierId, int productId,
                                                                     [FromBody] UpdateProductViewModel updateProductViewModel)
        {
            var command = new UpdateProductForSupplierCommand
            {
                SupplierId = supplierId,
                ProductId  = productId,
                Label      = updateProductViewModel.Label,
                Price      = updateProductViewModel.Price,
            };
            var result = await mediator.Send(command);

            if (!result.Success)
            {
                return(BadRequest(result.ErrorMessages));
            }

            var resultData = await mediator.Send(new GetProductForSupplierByIdQuery
                                                 { ProductId = result.Data, SupplierId = supplierId });

            return(Ok(ProductDto.FromCoreProductDto(resultData.Data)));
        }
コード例 #3
0
        public async Task <ActionResult <ProductDto> > AddProduct(int supplierId,
                                                                  [FromBody] CreateProductViewModel createProductViewModel)
        {
            var command = new CreateProductForSupplierCommand
            {
                SupplierId = supplierId,
                Label      = createProductViewModel.Label,
                Price      = createProductViewModel.Price,
            };
            var result = await mediator.Send(command);

            if (!result.Success)
            {
                return(BadRequest(result.ErrorMessages));
            }

            var resultData = await mediator.Send(new GetProductForSupplierByIdQuery
                                                 { ProductId = result.Data, SupplierId = supplierId });

            return(CreatedAtAction(nameof(GetProduct),
                                   new { supplierId = supplierId, productId = result.Data },
                                   ProductDto.FromCoreProductDto(resultData.Data)));
        }