public IActionResult GetOrderByOrderGuid(string orderGuid, string fields = "")
        {
            if (string.IsNullOrWhiteSpace(orderGuid))
            {
                return Error(HttpStatusCode.BadRequest, "orderGuid", "orderGuid");
            }

            var order = _orderApiService.GetOrderByOrderGuid(orderGuid);

            if (order == null)
            {
                return Error(HttpStatusCode.NotFound, "order", "not found");
            }

            var ordersRootObject = new OrdersRootObject();

            string decryptedCardNumber = _encryptionService.DecryptText(order.MaskedCreditCardNumber);
            if (!string.IsNullOrWhiteSpace(decryptedCardNumber))
            {
                order.CardNumber = decryptedCardNumber;
            }

            var orderDto = _dtoHelper.PrepareOrderDTO(order);
            ordersRootObject.Orders.Add(orderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject,fields);

            return new RawJsonActionResult(json);
        }
        public IActionResult GetOrders(OrdersParametersModel parameters)
        {
            if (parameters.Page < Constants.Configurations.DefaultPageValue)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter"));
            }

            if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit)
            {
                return(Error(HttpStatusCode.BadRequest, "page", "Invalid limit parameter"));
            }

            var storeId = _storeContext.CurrentStore.Id;

            var orders = _orderApiService.GetOrders(parameters.Ids, parameters.CreatedAtMin,
                                                    parameters.CreatedAtMax,
                                                    parameters.Limit, parameters.Page, parameters.SinceId,
                                                    parameters.Status, parameters.PaymentStatus, parameters.ShippingStatus,
                                                    parameters.CustomerId, storeId);

            IList <OrderDto> ordersAsDtos = orders.Select(x => _dtoHelper.PrepareOrderDTO(x)).ToList();

            var ordersRootObject = new OrdersRootObject
            {
                Orders = ordersAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Example #3
0
        public IActionResult GetOrderByInstantCheckoutOrderId(Guid id, string fields = "")
        {
            if (!IsRequestAuthorized())
            {
                return(Unauthorized());
            }

            if (id == Guid.Empty)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var order = _orderApiService.GetOrderByInstanCheckoutOrderId(id);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var ordersRootObject = new OrdersRootObject();

            var orderDto = _dtoHelper.PrepareOrderDTO(order);

            ordersRootObject.Orders.Add(orderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, fields);

            return(new RawJsonActionResult(json));
        }
Example #4
0
        public IActionResult CancelOrder(int id)
        {
            if (!IsRequestAuthorized())
            {
                return(Unauthorized());
            }

            if (id <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var orderToCancel = _orderApiService.GetOrderById(id);

            if (orderToCancel == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            _orderProcessingService.CancelOrder(orderToCancel, false);

            var ordersRootObject  = new OrdersRootObject();
            var cancelledOrderDto = _dtoHelper.PrepareOrderDTO(orderToCancel);

            ordersRootObject.Orders.Add(cancelledOrderDto);
            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Example #5
0
        public IActionResult GetOrderById(int id, string fields = "")
        {
            if (id <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var order = _orderApiService.GetOrderById(id);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var ordersRootObject = new OrdersRootObject();

            var restrictedAccess = _clientService.UserHasRestrictedAccess(User);
            var orderDto         = _dtoHelper.PrepareOrderDTO(order, restrictedAccess);

            ordersRootObject.Orders.Add(orderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, fields);

            return(new RawJsonActionResult(json));
        }
Example #6
0
        public IActionResult UpdateOrderAsPaid(int id)
        {
            if (!IsRequestAuthorized())
            {
                return(Unauthorized());
            }

            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            var orderPaid = MarkOrderAsPaid(id);

            if (!orderPaid)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var currentOrder = _orderApiService.GetOrderById(id);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(currentOrder);

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Example #7
0
        public IHttpActionResult GetOrdersByCustomerId(int customer_id)
        {
            IList <OrderDto> ordersForCustomer = _orderApiService.GetOrdersByCustomerId(customer_id).Select(x => x.ToDto()).ToList();

            var ordersRootObject = new OrdersRootObject()
            {
                Orders = ordersForCustomer
            };

            return(Ok(ordersRootObject));
        }
Example #8
0
        public async Task <IActionResult> GetOrdersByCustomerId(int customerId)
        {
            IList <OrderDto> ordersForCustomer = await _orderApiService.GetOrdersByCustomerId(customerId).SelectAwait(async x => await _dtoHelper.PrepareOrderDTOAsync(x)).ToListAsync();

            var ordersRootObject = new OrdersRootObject
            {
                Orders = ordersForCustomer
            };

            return(Ok(ordersRootObject));
        }
        public IActionResult GetOrdersByCustomerId(int customerId)
        {
            IList <OrderDto> ordersForCustomer = _orderApiService.GetOrdersByCustomerId(customerId).Select(x => _dtoHelper.PrepareOrderDTO(x)).ToList();

            var ordersRootObject = new OrdersRootObject
            {
                Orders = ordersForCustomer
            };

            return(Ok(ordersRootObject));
        }
Example #10
0
        public IActionResult GetOrdersByCustomerId(int customerId)
        {
            var restrictedAccess = _clientService.UserHasRestrictedAccess(User);
            IList <OrderDto> ordersForCustomer = _orderApiService.GetOrdersByCustomerId(customerId).Select(x => _dtoHelper.PrepareOrderDTO(x, restrictedAccess)).ToList();

            var ordersRootObject = new OrdersRootObject()
            {
                Orders = ordersForCustomer
            };

            return(Ok(ordersRootObject));
        }
Example #11
0
        public IHttpActionResult GetOrderById(int id, string fields = "")
        {
            if (id <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            Order order = _orderApiService.GetOrderById(id);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var ordersRootObject = new OrdersRootObject();

            OrderDto orderDto = order.ToDto();

            ordersRootObject.Orders.Add(orderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, fields);

            return(new RawJsonActionResult(json));
        }
Example #12
0
        public async Task <IActionResult> GetOrderById(int id, string fields = "")
        {
            if (id <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var order = _orderApiService.GetOrderById(id);

            if (order == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var ordersRootObject = new OrdersRootObject();

            var orderDto = await _dtoHelper.PrepareOrderDTOAsync(order);

            ordersRootObject.Orders.Add(orderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, fields);

            return(new RawJsonActionResult(json));
        }
        public IActionResult UpdateOrder(
            [ModelBinder(typeof(JsonModelBinder <OrderDto>))]
            Delta <OrderDto> orderDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            var currentOrder = _orderApiService.GetOrderById(orderDelta.Dto.Id);

            if (currentOrder == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var customer = currentOrder.Customer;

            var shippingRequired = currentOrder.OrderItems.Any(item => !item.Product.IsFreeShipping);

            if (shippingRequired)
            {
                var isValid = true;

                if (!string.IsNullOrEmpty(orderDelta.Dto.ShippingRateComputationMethodSystemName) ||
                    !string.IsNullOrEmpty(orderDelta.Dto.ShippingMethod))
                {
                    var storeId = orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id;

                    isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName ?? currentOrder.ShippingRateComputationMethodSystemName,
                                                 orderDelta.Dto.ShippingMethod,
                                                 storeId,
                                                 customer, BuildShoppingCartItemsFromOrderItems(currentOrder.OrderItems.ToList(), customer.Id, storeId));
                }

                if (isValid)
                {
                    currentOrder.ShippingMethod = orderDelta.Dto.ShippingMethod;
                }
                else
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            orderDelta.Merge(currentOrder);

            customer.BillingAddress  = currentOrder.BillingAddress;
            customer.ShippingAddress = currentOrder.ShippingAddress;

            _orderService.UpdateOrder(currentOrder);

            CustomerActivityService.InsertActivity("UpdateOrder",
                                                   LocalizationService.GetResource("ActivityLog.UpdateOrder"), currentOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(currentOrder);

            placedOrderDto.ShippingMethod = orderDelta.Dto.ShippingMethod;

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
        public IActionResult CreateOrder(
            [ModelBinder(typeof(JsonModelBinder <OrderDto>))]
            Delta <OrderDto> orderDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            if (orderDelta.Dto.CustomerId == null)
            {
                return(Error());
            }

            // We doesn't have to check for value because this is done by the order validator.
            var customer = CustomerService.GetCustomerById(orderDelta.Dto.CustomerId.Value);

            if (customer == null)
            {
                return(Error(HttpStatusCode.NotFound, "customer", "not found"));
            }

            var shippingRequired = false;

            if (orderDelta.Dto.OrderItems != null)
            {
                var shouldReturnError = AddOrderItemsToCart(orderDelta.Dto.OrderItems, customer, orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id);
                if (shouldReturnError)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }

                shippingRequired = IsShippingAddressRequired(orderDelta.Dto.OrderItems);
            }

            if (shippingRequired)
            {
                var isValid = true;

                isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName,
                                             orderDelta.Dto.ShippingMethod,
                                             orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id,
                                             customer,
                                             BuildShoppingCartItemsFromOrderItemDtos(orderDelta.Dto.OrderItems.ToList(),
                                                                                     customer.Id,
                                                                                     orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id));

                if (!isValid)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            var newOrder = _factory.Initialize();

            orderDelta.Merge(newOrder);

            customer.BillingAddress  = newOrder.BillingAddress;
            customer.ShippingAddress = newOrder.ShippingAddress;

            // If the customer has something in the cart it will be added too. Should we clear the cart first?
            newOrder.Customer = customer;

            // The default value will be the currentStore.id, but if it isn't passed in the json we need to set it by hand.
            if (!orderDelta.Dto.StoreId.HasValue)
            {
                newOrder.StoreId = _storeContext.CurrentStore.Id;
            }

            var placeOrderResult = PlaceOrder(newOrder, customer);

            if (!placeOrderResult.Success)
            {
                foreach (var error in placeOrderResult.Errors)
                {
                    ModelState.AddModelError("order placement", error);
                }

                return(Error(HttpStatusCode.BadRequest));
            }

            CustomerActivityService.InsertActivity("AddNewOrder",
                                                   LocalizationService.GetResource("ActivityLog.AddNewOrder"), newOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(placeOrderResult.PlacedOrder);

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Example #15
0
        public IActionResult UpdateOrder([ModelBinder(typeof(JsonModelBinder <OrderDto>))] Delta <OrderDto> orderDelta)
        {
            if (!IsRequestAuthorized())
            {
                return(Unauthorized());
            }

            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            var currentOrder = _orderApiService.GetOrderById(orderDelta.Dto.Id);

            if (currentOrder == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var customer = currentOrder.Customer;

            var shippingRequired = currentOrder.OrderItems.Any(item => !item.Product.IsFreeShipping);

            if (shippingRequired)
            {
                var isValid = true;

                if (!string.IsNullOrEmpty(orderDelta.Dto.ShippingRateComputationMethodSystemName) ||
                    !string.IsNullOrEmpty(orderDelta.Dto.ShippingMethod))
                {
                    var storeId = orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id;

                    isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName ?? currentOrder.ShippingRateComputationMethodSystemName,
                                                 orderDelta.Dto.ShippingMethod,
                                                 storeId,
                                                 customer, BuildShoppingCartItemsFromOrderItems(currentOrder.OrderItems.ToList(), customer.Id, storeId));
                }

                if (isValid)
                {
                    //Set the default Pickup Point

                    if (orderDelta.Dto.ShippingRateComputationMethodSystemName == "Pickup.PickupInStore")
                    {
                        var pickupPoints = _shippingService.GetPickupPoints(customer.BillingAddress,
                                                                            customer, null, _storeContext.CurrentStore.Id).PickupPoints.ToList();
                        var selectedPoint = pickupPoints.FirstOrDefault();
                        if (selectedPoint == null)
                        {
                            return(RedirectToRoute("CheckoutShippingAddress"));
                        }

                        var pickUpInStoreShippingOption = new ShippingOption
                        {
                            Name        = string.Format(_localizationService.GetResource("Checkout.PickupPoints.Name"), selectedPoint.Name),
                            Rate        = selectedPoint.PickupFee,
                            Description = selectedPoint.Description,
                            ShippingRateComputationMethodSystemName = selectedPoint.ProviderSystemName
                        };

                        _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, pickUpInStoreShippingOption, _storeContext.CurrentStore.Id);
                        _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.SelectedPickupPointAttribute, selectedPoint, _storeContext.CurrentStore.Id);
                    }
                    currentOrder.ShippingMethod = orderDelta.Dto.ShippingMethod;
                }
                else
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            orderDelta.Merge(currentOrder);

            customer.BillingAddress  = currentOrder.BillingAddress;
            customer.ShippingAddress = currentOrder.ShippingAddress;

            _orderService.UpdateOrder(currentOrder);

            _customerActivityService.InsertActivity("UpdateOrder",
                                                    base._localizationService.GetResource("ActivityLog.UpdateOrder"), currentOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(currentOrder);

            placedOrderDto.ShippingMethod = orderDelta.Dto.ShippingMethod;

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Example #16
0
        public IActionResult CreateOrder([ModelBinder(typeof(JsonModelBinder <OrderDto>))] Delta <OrderDto> orderDelta)
        {
            if (!IsRequestAuthorized())
            {
                return(Unauthorized());
            }

            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            //if (orderDelta.Dto.CustomerId == null)
            //    return Error();

            //TODO Add Guest Customer
            var customer = _customerService.InsertGuestCustomer();

            // We doesn't have to check for value because this is done by the order validator.
            //var customer = CustomerService.GetCustomerById(orderDelta.Dto.CustomerId.Value);

            if (customer == null)
            {
                return(Error(HttpStatusCode.NotFound, "customer", "not found"));
            }

            // Save default checkout attribute

            //save checkout attributes
            var attributesXml = "<Attributes><CheckoutAttribute ID='1'><CheckoutAttributeValue><Value>1</Value></CheckoutAttributeValue></CheckoutAttribute></Attributes>";

            _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.CheckoutAttributes, attributesXml, _storeContext.CurrentStore.Id);

            var shippingRequired = false;

            if (orderDelta.Dto.OrderItems != null)
            {
                var shouldReturnError = AddOrderItemsToCart(orderDelta.Dto.OrderItems, customer, orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id);
                if (shouldReturnError)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }

                shippingRequired = IsShippingAddressRequired(orderDelta.Dto.OrderItems);
            }

            if (shippingRequired)
            {
                var isValid = true;

                isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName,
                                             orderDelta.Dto.ShippingMethod,
                                             orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id,
                                             customer,
                                             BuildShoppingCartItemsFromOrderItemDtos(orderDelta.Dto.OrderItems.ToList(),
                                                                                     customer.Id,
                                                                                     orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id));

                if (!isValid)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            var newOrder = _factory.Initialize();

            orderDelta.Merge(newOrder);

            var country = _countryService.GetCountryByTwoLetterIsoCode(orderDelta.Dto.ShippingAddress.CountryCode);

            newOrder.BillingAddress.CountryId  = country.Id;
            newOrder.ShippingAddress.CountryId = country.Id;

            customer.BillingAddress  = newOrder.BillingAddress;
            customer.ShippingAddress = newOrder.ShippingAddress;


            //Set the default Pickup Point

            if (orderDelta.Dto.ShippingRateComputationMethodSystemName == "Pickup.PickupInStore")
            {
                var pickupPoints = _shippingService.GetPickupPoints(customer.BillingAddress,
                                                                    customer, null, _storeContext.CurrentStore.Id).PickupPoints.ToList();
                var selectedPoint = pickupPoints.FirstOrDefault();
                if (selectedPoint == null)
                {
                    return(RedirectToRoute("CheckoutShippingAddress"));
                }

                var pickUpInStoreShippingOption = new ShippingOption
                {
                    Name        = string.Format(_localizationService.GetResource("Checkout.PickupPoints.Name"), selectedPoint.Name),
                    Rate        = selectedPoint.PickupFee,
                    Description = selectedPoint.Description,
                    ShippingRateComputationMethodSystemName = selectedPoint.ProviderSystemName
                };

                _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, pickUpInStoreShippingOption, _storeContext.CurrentStore.Id);
                _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.SelectedPickupPointAttribute, selectedPoint, _storeContext.CurrentStore.Id);
            }

            // If the customer has something in the cart it will be added too. Should we clear the cart first?
            newOrder.Customer = customer;

            // The default value will be the currentStore.id, but if it isn't passed in the json we need to set it by hand.
            if (!orderDelta.Dto.StoreId.HasValue)
            {
                newOrder.StoreId = _storeContext.CurrentStore.Id;
            }

            var placeOrderResult = PlaceOrder(orderDelta.Dto.OrderGuid, newOrder, customer);

            if (!placeOrderResult.Success)
            {
                foreach (var error in placeOrderResult.Errors)
                {
                    ModelState.AddModelError("order placement", error);
                }

                return(Error(HttpStatusCode.BadRequest));
            }

            _customerActivityService.InsertActivity("AddNewOrder",
                                                    base._localizationService.GetResource("ActivityLog.AddNewOrder"), newOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(placeOrderResult.PlacedOrder);

            placedOrderDto.OrderGuid = placeOrderResult.PlacedOrder.OrderGuid;

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Example #17
0
        public ActionResult CreateOrder(orderModelApi orderDelta)
        {
            // Here we display the errors if the validation has failed at some point.


            bool     shippingRequired = false;
            Customer customer         = _customerService.GetCustomerById(orderDelta.CustomerId.Value);

            if (orderDelta.OrderItemDtos != null)
            {
                bool shouldReturnError = ValidateEachOrderItem(orderDelta.OrderItemDtos);

                if (shouldReturnError)
                {
                }

                shouldReturnError = AddOrderItemsToCart(orderDelta.OrderItemDtos, customer, orderDelta.StoreId ?? _storeContext.CurrentStore.Id);



                shippingRequired = IsShippingAddressRequired(orderDelta.OrderItemDtos);
            }

            if (shippingRequired)
            {
                bool isValid = true;

                isValid &= SetShippingOption(orderDelta.ShippingRateComputationMethodSystemName,
                                             orderDelta.ShippingMethod,
                                             orderDelta.StoreId ?? _storeContext.CurrentStore.Id,
                                             customer,
                                             BuildShoppingCartItemsFromOrderItemDtos(orderDelta.OrderItemDtos.ToList(),
                                                                                     customer.Id,
                                                                                     orderDelta.StoreId ?? _storeContext.CurrentStore.Id));

                //isValid &= ValidateAddress(orderDelta.ShippingAddress, "shipping_address");

                //if (!isValid)
                //{
                //    return Error(HttpStatusCode.BadRequest);
                //}
            }

            //if (!OrderSettings.DisableBillingAddressCheckoutStep)
            //{
            //    bool isValid = ValidateAddress(orderDelta.Dto.BillingAddress, "billing_address");

            //    if (!isValid)
            //    {
            //        return Error(HttpStatusCode.BadRequest);
            //    }
            //}



            Core.Domain.Orders.Order newOrder = new Core.Domain.Orders.Order();

            newOrder.BillingAddress.Address1 = orderDelta.BillingAddress.Address1;
            newOrder.BillingAddress.Address2 = orderDelta.BillingAddress.Address2;
            newOrder.BillingAddress.City     = orderDelta.BillingAddress.City;

            newOrder.BillingAddress.Company            = orderDelta.BillingAddress.Company;
            newOrder.BillingAddress.Country.Name       = orderDelta.BillingAddress.CountryName;
            newOrder.BillingAddress.CountryId          = orderDelta.BillingAddress.CountryId;
            newOrder.BillingAddress.Email              = orderDelta.BillingAddress.Email;
            newOrder.BillingAddress.FaxNumber          = orderDelta.BillingAddress.FaxNumber;
            newOrder.BillingAddress.FirstName          = orderDelta.BillingAddress.FirstName;
            newOrder.BillingAddress.LastName           = orderDelta.BillingAddress.LastName;
            newOrder.BillingAddress.PhoneNumber        = orderDelta.BillingAddress.PhoneNumber;
            newOrder.BillingAddress.StateProvince.Name = orderDelta.BillingAddress.StateProvinceName;
            newOrder.BillingAddress.StateProvinceId    = orderDelta.BillingAddress.StateProvinceId;
            newOrder.BillingAddress.ZipPostalCode      = orderDelta.BillingAddress.ZipPostalCode;
            newOrder.BillingAddress.CreatedOnUtc       = orderDelta.BillingAddress.CreatedOnUtc;



            newOrder.ShippingAddress.Address1 = orderDelta.ShippingAddress.Address1;
            newOrder.ShippingAddress.Address2 = orderDelta.ShippingAddress.Address2;
            newOrder.ShippingAddress.City     = orderDelta.ShippingAddress.City;

            newOrder.ShippingAddress.Company            = orderDelta.ShippingAddress.Company;
            newOrder.ShippingAddress.Country.Name       = orderDelta.ShippingAddress.CountryName;
            newOrder.ShippingAddress.CountryId          = orderDelta.ShippingAddress.CountryId;
            newOrder.ShippingAddress.Email              = orderDelta.ShippingAddress.Email;
            newOrder.ShippingAddress.FaxNumber          = orderDelta.ShippingAddress.FaxNumber;
            newOrder.ShippingAddress.FirstName          = orderDelta.ShippingAddress.FirstName;
            newOrder.ShippingAddress.LastName           = orderDelta.ShippingAddress.LastName;
            newOrder.ShippingAddress.PhoneNumber        = orderDelta.ShippingAddress.PhoneNumber;
            newOrder.ShippingAddress.StateProvince.Name = orderDelta.ShippingAddress.StateProvinceName;
            newOrder.ShippingAddress.StateProvinceId    = orderDelta.ShippingAddress.StateProvinceId;
            newOrder.ShippingAddress.ZipPostalCode      = orderDelta.ShippingAddress.ZipPostalCode;
            newOrder.ShippingAddress.CreatedOnUtc       = orderDelta.ShippingAddress.CreatedOnUtc;
            // If the customer has something in the cart it will be added too. Should we clear the cart first?
            newOrder.Customer   = customer;
            newOrder.OrderItems = orderDelta.OrderItemDtos;
            // The default value will be the currentStore.id, but if it isn't passed in the json we need to set it by hand.
            if (!orderDelta.StoreId.HasValue)
            {
                newOrder.StoreId = _storeContext.CurrentStore.Id;
            }

            PlaceOrderResult placeOrderResult = PlaceOrder(newOrder, customer);

            if (!placeOrderResult.Success)
            {
                foreach (var error in placeOrderResult.Errors)
                {
                    // ModelState.AddModelError("order placement", error);
                }

                // return Error(HttpStatusCode.BadRequest);
            }

            //   _customerActivityService.InsertActivity("AddNewOrder",_localizationService.GetResource("ActivityLog.AddNewOrder"), newOrder.Id);

            var ordersRootObject = new OrdersRootObject();

            OrderDto placedOrderDto = placeOrderResult.PlacedOrder.();

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = _jsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }