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)); }
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))); }
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))); }