Ejemplo n.º 1
0
        public async Task <ProductDto> Handle(PutProductCommand request, CancellationToken cancellationToken)
        {
            var product = new Product()
            {
                Id = request.Id, CountInStock = request.CountInStock, Price = request.Price, Title = request.Title, Manufacturer = _productDxos.MapManufacturer(request.Manufacturer)
            };
            await _productDatabase.ReplaceOneAsync(i => i.Id == product.Id, product);

            var productDto = _productDxos.MapProductDto(product);

            return(productDto);
        }
        public async Task <ProductDto> Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var product = new Product()
            {
                CountInStock = request.CountInStock, Price = request.Price, Title = request.Title, Manufacturer = _productDxos.MapManufacturer(request.Manufacturer)
            };
            await _productDatabase.InsertOneAsync(product);

            await _mediator.Publish(new Domain.Events.ItemCreatedEvent(product.Id, "product"), cancellationToken);

            var productDto = _productDxos.MapProductDto(product);

            return(productDto);
        }