Пример #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);
        }
Пример #2
0
        public async Task <ProductDto> Handle(GetProductrQuery request, CancellationToken cancellationToken)
        {
            var product = (await _productDatabase.GetAsync(i => i.Id == request.Id)).SingleOrDefault();

            if (product != null)
            {
                Console.WriteLine($"Got a request get product Id: {product.Id}");
                var productDto = _productDxos.MapProductDto(product);
                return(productDto);
            }
            // return Task.FromResult(_productDatabase.GetOne(i => i.Id == request.Id));
            return(null);
        }
        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);
        }