public GetEntityResult<ExternalActivityViewModel> DownLoadExternalOrders(OrderSearchOptions orderSearchOptions)
        {
            GetEntityResult<ExternalActivityViewModel> externalActivityResult = new GetEntityResult<ExternalActivityViewModel>() { Success = false };

            ExternalOrderResult orderResult = null;

            orderSearchOptions.ToDate = DateTime.Now;

            orderResult = new ExternalOrderClient().GetUnshippedOrders(orderSearchOptions);

            if (orderResult.Success)
            {
                EntityOperationResultBase saveResult = SaveExternalOrder(orderResult.Orders);

            }
            else
            {
                externalActivityResult.ErrorMessage = "Error occurred while retrieving orders for " + orderSearchOptions.StoreProvider.ToString();

                return externalActivityResult;
            }

            ExternalActivityViewModel activity = new ExternalActivityViewModel()
            {
                ActivityStatus = ExternalActivityStatus.Completed,
                ExternalActivityType = ExternalActivityTypeEnum.GetUnshippedOrders,
                StoreProviderType = orderSearchOptions.StoreProvider,
                LastPerformedOn = orderSearchOptions.ToDate,
            };

            try
            {
                UpdateResult<ExternalActivity> externalActivityUpdateResult = UpdateExternalActivityDetails(activity);

                GetEntityResult<ExternalActivityViewModel> result = GetLastExternalActivityDetails(ExternalActivityTypeEnum.GetUnshippedOrders, orderSearchOptions.StoreProvider);

                externalActivityResult.Success = result.Success;
                externalActivityResult.Entity = result.Entity;

            }
            catch (Exception ex)
            {
                externalActivityResult.Success = false;
                externalActivityResult.ErrorMessage = "Error occurred while update activity details. Please refresh the page";
            }

            return externalActivityResult;
        }
        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;
        }