public Task <int> Handle(AddOrderCommand request, CancellationToken cancellationToken) { Orders newOrder = new Orders(request.UserId, DateTime.Now, OrderStatus.Draft, request.Payment.CreditCartNumber, request.Payment.Cvv, request.Payment.ExpiredDate, request.Payment.OwnerName, request.ContactMail); foreach (var product in request.Products) { newOrder.AddProduct(product.Id, product.ProductCount, product.Price, product.ProductName, product.ProductCode); } orderRepository.AddNewOrder(newOrder); List <ProductsInStockViewModel> productsToReserve = new List <ProductsInStockViewModel>(); newOrder.Products.ToList().ForEach(x => productsToReserve.Add(new ProductsInStockViewModel() { ProductId = x.ProductId, OrderProductCancelCount = x.OrderCount })); ReserveProductsMessage(new ReduceProductInStockCommand(newOrder.Id, productsToReserve)); return(Task.FromResult(newOrder.Id)); }