public UpdateResult<ExternalOrderViewModel> UpdateExternalOrderShipped(ExternalOrderViewModel order)
        {
            UpdateResult<ExternalOrderViewModel> updateResult = new UpdateResult<ExternalOrderViewModel>();

            using (InnoventoryDBContext dbContext = new InnoventoryDBContext())
            {

                DbSet<ExternalOrder> externalOrderSet = dbContext.ExternalOrderSet;

                ExternalOrder existingOrder = externalOrderSet.Where(x => x.StoreProviderOrderId == order.StoreProviderOrderId).FirstOrDefault();

                if (existingOrder != null)
                {
                    existingOrder.OrderStatus = (int)StoreOrderStatusEnum.Shipped;
                }

            }

            return updateResult;
        }
        public ExternalOrderViewModelResult GetExternalOrders(OrderSearchOptions orderSearchOptions)
        {
            ExternalOrderViewModelResult result = new ExternalOrderViewModelResult()
            {
                Success = false,
                ExternalOrderViewModels = new List<ExternalOrderViewModel>(),
            };

            DateTime fromDate = orderSearchOptions.FromDate;
            DateTime toDate = orderSearchOptions.ToDate;

            DbSet<ExternalOrder> externalOrderSet = new InnoventoryDBContext().ExternalOrderSet;

            DateTime from = Utility.ConvertToGMT(fromDate);

            DateTime to = Utility.ConvertToGMT(toDate);

            int storeType = (int)orderSearchOptions.StoreProvider;

            var dbExternalOrders = externalOrderSet.Where(x => x.OrderDate >= from && x.OrderDate <= to && x.StoreProviderId == storeType).OrderByDescending(y => y.OrderDate).ToList();

            if (dbExternalOrders.Count > 0)
            {
                foreach (var order in dbExternalOrders)
                {
                    ExternalOrderViewModel vm = new ExternalOrderViewModel(order);

                    result.ExternalOrderViewModels.Add(vm);
                }
            }
            else
            {
                result.ErrorMessage = "No unshipped orders found...";
            }

            return result;
        }
        public ExternalOrderViewModelResult GetExternalOrdersByProvider(int providerId)
        {
            ExternalOrderViewModelResult result = new ExternalOrderViewModelResult()
            {
                Success = false,
                ExternalOrderViewModels = new List<ExternalOrderViewModel>(),
            };

            using (InnoventoryDBContext dbContext = new InnoventoryDBContext())
            {
                DbSet<ExternalOrder> externalOrderSet = dbContext.ExternalOrderSet;

                DbSet<ExternalOrderLineItem> orderItemSet = dbContext.ExternalOrderLineItemSet;

                var dbExternalOrders = externalOrderSet.Where(x => x.StoreProviderId == providerId && x.OrderStatus == (int)StoreOrderStatusEnum.Unshipped).OrderByDescending(y => y.OrderDate).ToList();

                if (dbExternalOrders.Count > 0)
                {
                    int serialNo = 0;
                    foreach (var order in dbExternalOrders)
                    {
                        serialNo += 1;

                        List<ExternalOrderLineItem> orderItems = orderItemSet.Where(x => x.StoreOrderId == order.StoreOrderHeaderId).ToList();

                        order.ExternalOrderLineItems = orderItems;

                        ExternalOrderViewModel vm = new ExternalOrderViewModel(order);

                        vm.SerialNo = serialNo;

                        result.ExternalOrderViewModels.Add(vm);
                    }

                    result.Success = true;
                }
                else
                {
                    result.ErrorMessage = "No unshipped orders found...";
                }
            }

            return result;
        }