Пример #1
0
        public async Task <PlaceOrderResponse> PlaceOrder(PlaceOrderRequest request)
        {
            //Perform domain validation
            if (CanPlaceOrder(request))
            {
                var domainOrder = new Domain.Order()
                {
                    DatePlaced       = DateTime.Now,
                    CustomerId       = request.Order.CustomerId,
                    PromotionCode    = request.Order.PromotionCode,
                    BillingAddress   = request.Order.BillingAddress,
                    OrderLines       = request.Order.OrderLines,
                    ShippingAddress  = request.Order.ShippingAddress,
                    ShippingCost     = request.Order.ShippingCost,
                    TotalCost        = request.Order.TotalCost,
                    TransitLocations = request.Order.TransitLocations
                };
                //store the order in the repository
                await _unitOfWork.OrderRepos.AddAsync(domainOrder);

                _unitOfWork.Complete();
                var response = PlaceOrderResponse.Create(true, string.Empty, domainOrder.Id);
                //publish
                //_publisher.Publish(MapToContract(domainOrder, orderId));
                return(response);
            }
            else
            {
                var response = PlaceOrderResponse.Create(false, "Order validation failed", null);
                return(response);
            }
        }
Пример #2
0
        public PlaceOrderResponse PlaceOrder(PlaceOrderRequest request)
        {
            //Create domain order from the request
            var domainOrder = Domain.Order.Create(
                orderLines: request.Order.OrderLines.Select(line => Domain.OrderLine.Create(
                                                                product: Domain.Product.Create(
                                                                    stockcode: line.Product.Stockcode,
                                                                    productImageUrl: line.Product.ProductImageUrl,
                                                                    volumetricWeight: line.Product.VolumetricWeight
                                                                    ),
                                                                quantity: line.Quantity,
                                                                unitPrice: line.UnitPrice
                                                                )).ToList(),
                customerId: request.Order.CustomerId,
                billingAddress: Domain.Address.Create(request.Order.BillingAddress.AddressLine1,
                                                      request.Order.BillingAddress.AddressLine2,
                                                      request.Order.BillingAddress.Country),
                shippingAddress: Domain.Address.Create(request.Order.ShippingAddress.AddressLine1,
                                                       request.Order.ShippingAddress.AddressLine2,
                                                       request.Order.ShippingAddress.Country),
                promotionCode: request.Order.PromotionCode,
                datePlaced: request.Order.DatePlaced,
                costCalculatorService: _costCalculatorService,
                productAvailabilityService: _productAvailabilityService,
                orderTrackingRepository: _orderTrackingRepository
                );

            //Perform domain validation
            if (domainOrder.CanPlaceOrder(request.ExpectedTotalCost, request.ExpectedShippingCost))
            {
                //store the order in the repository
                var orderId  = _orderRepository.Store(domainOrder);
                var response = PlaceOrderResponse.Create(true, string.Empty, orderId);
                //publish
                _publisher.Publish(MapToContract(domainOrder, orderId));
                return(response);
            }
            else
            {
                var response = PlaceOrderResponse.Create(false, "Order validation failed", null);
                return(response);
            }
        }