public async Task <OrderDto> Handle(PutOrderCommand request, CancellationToken cancellationToken)
        {
            var order = new Order()
            {
                Id = request.Id, UserName = request.UserName, ProductIDs = request.ProductIDs.Select(y => new MongoDBRef(ProductRepository.collectionName, y)).ToList()
            };
            await _orderDatabase.ReplaceOneAsync(i => i.Id == order.Id, order);

            var orderDto = _customDxos.MapOrderDto(order);

            return(orderDto);
        }
Beispiel #2
0
        public async Task <OrderDto> Handle(GetOrderQuery request, CancellationToken cancellationToken)
        {
            var Order = (await _orderDatabase.GetAsync(i => i.Id == request.Id)).SingleOrDefault();

            if (Order != null)
            {
                Console.WriteLine($"Got a request get Order Id: {Order.Id}");
                var OrderDto = _cutomDxos.MapOrderDto(Order);
                return(OrderDto);
            }
            // return Task.FromResult(_OrderDatabase.GetOne(i => i.Id == request.Id));
            return(null);
        }
        public async Task <OrderDto> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var order = new Order()
            {
                UserName = request.UserName, ProductIDs = request.ProductIDs.Select(y => new MongoDBRef(ProductRepository.collectionName, y)).ToList()
            };
            await _orderDatabase.InsertOneAsync(order);

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

            var orderDto = _customDxos.MapOrderDto(order);

            return(orderDto);
        }