コード例 #1
0
        public async Task <IActionResult> DeleteProduct([FromRoute] int id)
        {
            _logger.LogInformation($"DeleteProduct({id})");

            if (!ModelState.IsValid)
            {
                _logger.LogWarning($"DeleteProduct({id}) invalid ModelState: {ModelState.ErrorsToString()}");
                return(BadRequest(ModelState));
            }

            var product = await _productService.GetByIdAsync(id);

            if (product == null)
            {
                _logger.LogWarning($"DeleteProduct({id}) not found");
                return(NotFound());
            }

            await _productService.DeleteAsync(id);

            // Notify about the sale
            // No waiting for completion
            _notifyService?.ProductSold(product);

            return(Ok(product));
        }