Exemplo n.º 1
0
        static Boolean AddJetOrder(dynamic order)
        {
            using (var context = new NetsuiteIntegrationEntities())
            {
                try
                {
                    String emailAddress = "";
                    if (!String.IsNullOrWhiteSpace(order.hash_email.Value))
                    {
                        emailAddress = order.hash_email.Value;
                    }

                    Decimal basePrice      = Convert.ToDecimal(order.order_totals.item_price.base_price.Value);
                    Decimal shippingCost   = Convert.ToDecimal(order.order_totals.item_price.item_shipping_cost.Value);
                    Decimal tax            = Convert.ToDecimal(order.order_totals.item_price.item_shipping_tax.Value);
                    Decimal feeAdjustments = 0;
                    if (!String.IsNullOrEmpty(order.order_totals.fee_adjustments))
                    {
                        feeAdjustments = Convert.ToDecimal(order.order_totals.fee_adjustments.Value);
                    }
                    Decimal grandTotal = basePrice + shippingCost + tax - feeAdjustments;

                    JetOrder jetOrder = new JetOrder
                    {
                        JetOrderId      = order.reference_order_id.Value,
                        BillToName      = order.buyer.name.Value,
                        BillToAddress1  = order.shipping_to.address.address1.Value,
                        BillToAddress2  = order.shipping_to.address.address2.Value,
                        BillToCity      = order.shipping_to.address.city.Value,
                        BillToCountry   = "USA",
                        BillToEmail     = emailAddress,
                        BillToPhone     = order.buyer.phone_number.Value,
                        BillToState     = order.shipping_to.address.state.Value,
                        BillToZip       = order.shipping_to.address.zip_code.Value,
                        RecipientName   = order.shipping_to.recipient.name.Value,
                        ShipToAddress1  = order.shipping_to.address.address1.Value,
                        ShipToAddress2  = order.shipping_to.address.address2.Value,
                        ShipToCity      = order.shipping_to.address.city.Value,
                        ShipToCountry   = "USA",
                        ShipToEmail     = emailAddress,
                        ShipToPhone     = order.buyer.phone_number.Value,
                        ShipToState     = order.shipping_to.address.state.Value,
                        ShipToZip       = order.shipping_to.address.zip_code.Value,
                        Discount        = feeAdjustments,
                        GrandTotal      = grandTotal,
                        Handling        = 0,
                        OrderDateTime   = order.order_placed_date,
                        PaymentType     = "Credit Card",
                        SubTotal        = basePrice,
                        Shipping        = shippingCost,
                        Tax             = tax,
                        MerchantOrderId = order.merchant_order_id.Value
                    };

                    for (var i = 0; i < ((Newtonsoft.Json.Linq.JContainer)(order.order_items)).Count; i++)
                    {
                        Boolean ret = HelperClass.AddJetOrderLine(order.order_items[i], order.reference_order_id.Value);
                        if (!ret)
                        {
                            throw new Exception("Order Line Failed");
                        }
                    }
                    context.JetOrders.Add(jetOrder);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(false);
                }
                return(true);
            }
        }