public ExternalOrderShippedResult SetOrdersShipped(ApiOrderShipmentRequest request)
        {
            ExternalOrderShippedResult result = null;
            IOrderShipmentRequest shipmentRequests = null;
            List<IOrderShipmentInfo> shipmentList = new List<IOrderShipmentInfo>();

            IExternalStoreService externalService = null;

            if (request.StoreProvider == StoreProviderTypeEnum.eBay)
            {
                shipmentRequests = new eBayShipmentRequest();

                foreach (var item in request.ShippedOrders)
                {
                    shipmentList.Add(new eBayOrderShipmentIfo
                    {

                        OrderId = item.StoreProviderOrderId,
                        IsPartialShipment = false,
                        StoreProvider = StoreProviderTypeEnum.eBay,
                        TrackingNo = "0",
                        ShipmentDate = Utility.ConvertToGMT(DateTime.UtcNow),
                        ExternalOrderHeaderId = item.ExternalOrderHeaderId,
                    });

                }

                externalService = new eBayServiceCall();

            }

            if (request.StoreProvider == StoreProviderTypeEnum.Amazon)
            {

                shipmentRequests = new AmazonOrderShipmentRequest();

                foreach (var item in request.ShippedOrders)
                {

                    shipmentList.Add(new AmazonOrderShipmentInfo
                    {

                        OrderId = item.StoreProviderOrderId,
                        IsPartialShipment = false,
                        StoreProvider = StoreProviderTypeEnum.Amazon,
                        TrackingNo = "0",
                        ShipmentDate = DateTime.UtcNow.AddMinutes(-10),
                    });

                }

                externalService = new AmazonServiceClient();
                //result = new ExternalOrderShippedResult() { Success = false, ErrorMessage = "Yet not implemented" };
                //return result;
            }

            shipmentRequests.ShipmentList = shipmentList;

            result = externalService.SetOrderShipped(shipmentRequests);

            return result;
        }
        public ExternalOrderShippedResult SetExternalOrderShipped(ApiOrderShipmentRequest orderShipmentRequest)
        {
            ExternalOrderShippedResult shippedResult = new ExternalOrderShippedResult();

            shippedResult = new ExternalOrderClient().SetOrdersShipped(orderShipmentRequest);

            try
            {
                if (shippedResult != null && shippedResult.ShippingResults.Count > 0)
                {
                    using (InnoventoryDBContext dbContext = new InnoventoryDBContext())
                    {
                        DbSet<ExternalOrder> externalOrderSet = dbContext.ExternalOrderSet;

                        foreach (ShippingResult shippingResult in shippedResult.ShippingResults)
                        {

                            ExternalOrder shippedOrder = externalOrderSet.Where(x => x.StoreOrderHeaderId == shippingResult.ExternalOrderHeaderId).FirstOrDefault();

                            if (shippedOrder != null)
                            {

                                if (shippingResult.Success)
                                {
                                    try
                                    {
                                        shippedOrder.ShippedDate = shippingResult.ShippedDate.Value;
                                        shippedOrder.OrderStatus = (int)StoreOrderStatusEnum.Shipped;

                                        shippedOrder.StoreOrderStatus = StoreOrderStatusEnum.Shipped.ToString();

                                        externalOrderSet.Attach(shippedOrder);

                                        dbContext.Entry(shippedOrder).State = EntityState.Modified;

                                        dbContext.SaveChanges();
                                    }
                                    catch(DbEntityValidationException dbEx)
                                    {
                                        string errorMessage = string.Join("; ", dbEx.EntityValidationErrors);
                                        shippedResult.ErrorMessage = shippedResult.ErrorMessage + "; " + errorMessage;
                                    }
                                }

                            }

                        }

                    }

                    shippedResult.Success = true;
                }
            }

            catch (Exception ex)
            {

                shippedResult.ErrorMessage = shippedResult.ErrorMessage + "; " +ex.Message;
                shippedResult.Success = false;
            }

            return shippedResult;
        }