Beispiel #1
0
 //maybe this could also be done with automapper in future using json annotations
 //in source dto model
 public SalesOrderDto MapFomDedicated(EcpSalesOrderDto dedicatedOrder)
 {
     return(new SalesOrderDto
     {
         OrderNumber = dedicatedOrder.order_header.order_number,
         OrderDateTime = DateTime.Parse(dedicatedOrder.order_header.order_datetime),
         ShippingType = dedicatedOrder.logistical_units.First().shipping_type,
         OrderOrigin = new SalesOrderOriginDto
         {
             SalesChannel = dedicatedOrder.order_header.origin.sales_channel,
             SalesLocation = dedicatedOrder.order_header.origin.locale
         },
         Discounts = MapDiscounts(dedicatedOrder.order_header.discounts),
         Payments = MapPayments(dedicatedOrder.order_header.payments),
         TotalPrices = new SalesOrderTotalPriceDto
         {
             ShippingStandardGross = dedicatedOrder.order_header.totals.shipping_totals_gross.standard,
             ShippingExpressGross = dedicatedOrder.order_header.totals.shipping_totals_gross.express,
             ShippingBulkyGoodsGross = dedicatedOrder.order_header.totals.shipping_totals_gross.bulky_goods,
             ShippingDangerousGoodsGross = dedicatedOrder.order_header.totals.shipping_totals_gross.dangerous_goods,
             TotalDiscountGrossPrice = dedicatedOrder.order_header.totals.total_discount_gross,
             PaymentExpensesGrossPrices = new SalesOrderPaymentExpensesGrossDto
             {
                 CashOnDelivery = dedicatedOrder.order_header.totals.payment_expenses_gross.cash_on_delivery
             }
         },
         Customer = new SalesOrderCustomerDto
         {
             Email = dedicatedOrder.order_header.customer.customer_email
         },
         BillingAddress = new SalesOrderAddressDto
         {
             FirstName = dedicatedOrder.order_header.billing_address.first_name,
             LastName = dedicatedOrder.order_header.billing_address.last_name,
             Street1 = dedicatedOrder.order_header.billing_address.street1,
             Street2 = dedicatedOrder.order_header.billing_address.street2,
             Street3 = dedicatedOrder.order_header.billing_address.street3,
             ZipCode = dedicatedOrder.order_header.billing_address.zip_code,
             City = dedicatedOrder.order_header.billing_address.city,
             PhoneNumber = dedicatedOrder.order_header.billing_address.phone_number,
             CountryCode = dedicatedOrder.order_header.billing_address.country_code,
             Type = AddressType.Billing
         },
         ShippingAddresses = MapShippingAddresses(dedicatedOrder.order_header.shipping_addresses),
         OrderItems = MapItems(dedicatedOrder.order_rows)
     });
 }
        public async Task <IActionResult> Post([FromBody] EcpSalesOrderDto orderData)
        {
            this.appLogger.LogInformation($"start processing sales order number: {orderData.order_header.order_number}");

            var order = this.orderMapper.MapFomDedicated(orderData);

            var stringContent = new StringContent(JsonConvert.SerializeObject(order), Encoding.UTF8, "application/json");

            var uri = Environment.GetEnvironmentVariable("SALES_ORDER_ECP_PROVIDER_SALES_ORDER_API_URL") + configuration["SalesOrderApiPostRoute"];

            var responseMessage = await httpClient.PostAsync(new Uri(uri), stringContent);

            if ((int)responseMessage.StatusCode < 400)
            {
                resultMessage = "successfully imported!";
                this.appLogger.LogInformation(resultMessage);
                return(Ok(resultMessage));
            }

            resultMessage = $"error on importing!\n\n{responseMessage.Content.ReadAsStringAsync().Result}";
            this.appLogger.LogError(resultMessage);
            return(BadRequest(resultMessage));
        }