public bool OrdersEOD()
        {
            Console.WriteLine("End Of process starts at: " + DateTime.Now);
            OrdersRepositoryDbMethods ordersRepositoryDbMethods = new OrdersRepositoryDbMethods();
            Orders          order        = new Orders();
            List <OrderDto> listOfOrders = ordersRepositoryDbMethods.ReadAllEodOrderDataToRepository();

            foreach (var listOfOrder in listOfOrders)
            {
                log.Info("//--------------------------------------------------------------------------------------------");
                log.Info("End of day for invoice starts: " + listOfOrder.InvoiceNumber + " at: " + DateTime.Now.ToString());
                if (!string.IsNullOrEmpty(listOfOrder.InvoiceNumber))
                {
                    try
                    {
                        order.UpdateOrderByInvoice(listOfOrder.InvoiceNumber, listOfOrder.TrackingCode);
                        ordersRepositoryDbMethods.RemoveOrderFromOrderDataToRepository(listOfOrder.InvoiceNumber);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error processing: " + listOfOrder.InvoiceNumber + " ,Error: " + ex.Message);
                    }
                    //ordersRepositoryDbMethods.RemoveOrderFromMyEODShipmentRepository(listOfOrder.InvoiceNumber);*/
                }
                log.Info("End of day for invoice ends: " + listOfOrder.InvoiceNumber + " at: " + DateTime.Now.ToString());
            }
            Console.WriteLine("End Of process ends at: " + DateTime.Now);
            return(ordersRepositoryDbMethods.CleanOrderDataToRepository());
        }
        public bool CreateShippingInformation(XDocument xdoc, OrderDto orderDto)
        {
            var context = new orderstatusEntities();
            OrdersRepositoryDbMethods ordersRepositoryDbMethods = new OrdersRepositoryDbMethods();

            try
            {
                int carrierType = 0;
                // <Shipment>
                dynamic shippingInformation = from x in xdoc.Descendants("Shipment")
                                              select new
                {
                    ShipmentID      = x.Descendants("ShipmentID").First().Value != string.Empty ?  x.Descendants("ShipmentID").First().Value:"",
                    ShipmentDate    = x.Descendants("ShipmentDate").First().Value != string.Empty ?  x.Descendants("ShipmentDate").First().Value:"",
                    Method          = x.Descendants("Method").First().Value != string.Empty ?  x.Descendants("Method").First().Value:"",
                    FirstName       = x.Descendants("FirstName").First().Value != string.Empty ?  x.Descendants("FirstName").First().Value:"",
                    LastName        = x.Descendants("LastName").First().Value != string.Empty ? x.Descendants("LastName").First().Value : "",
                    Company         = x.Descendants("Company").First().Value != string.Empty ? x.Descendants("Company").First().Value : "",
                    Address         = x.Descendants("Address").First().Value != string.Empty ? x.Descendants("Address").First().Value : "",
                    Address2        = x.Descendants("Address2").First().Value != string.Empty ? x.Descendants("Address2").First().Value : "",
                    City            = x.Descendants("City").First().Value != string.Empty ? x.Descendants("City").First().Value : "",
                    ZipCode         = x.Descendants("ZipCode").First().Value != string.Empty ? x.Descendants("ZipCode").First().Value : "",
                    StateCode       = x.Descendants("StateCode").First().Value != string.Empty ? x.Descendants("StateCode").First().Value : "",
                    CountryCode     = x.Descendants("CountryCode").First().Value != string.Empty ? x.Descendants("CountryCode").First().Value : "",
                    Phone           = x.Descendants("Phone").First().Value != string.Empty ? x.Descendants("Phone").First().Value : "",
                    Weight          = x.Descendants("Weight").First().Value != string.Empty ? x.Descendants("Weight").First().Value : "",
                    Status          = x.Descendants("Status").First().Value != string.Empty ? x.Descendants("Status").First().Value : "",
                    InternalComment = x.Descendants("InternalComment").First().Value != string.Empty ? x.Descendants("InternalComment").First().Value : "",
                    TrackingCode    = x.Descendants("TrackingCode").First().Value,
                };
                foreach (var ship in shippingInformation)
                {
                    var firstName = (ship.FirstName != null) ? ship.FirstName.ToString() : "";
                    var lastName  = (ship.LastName != null) ? ship.LastName.ToString() : "";
                    orderDto.Name         = firstName + " " + lastName;
                    orderDto.Company      = (ship.Company != null) ? ship.Company.ToString() : "";
                    orderDto.Address      = (ship.Address != null) ? ship.Address.ToString() : "";
                    orderDto.Address2     = (ship.Address2 != null) ? ship.Address2.ToString() : "";
                    orderDto.City         = (ship.City != null) ? ship.City.ToString() : "";
                    orderDto.Zip          = (ship.ZipCode != null) ? ship.ZipCode.ToString() : "";
                    orderDto.State        = (ship.StateCode != null) ? ship.StateCode.ToString() : "";
                    orderDto.Country      = (ship.CountryCode != null) ? ship.CountryCode.ToString() : "";
                    orderDto.Phone        = (ship.Phone != null) ? ship.Phone.ToString() : "";
                    orderDto.TrackingCode = (ship.TrackingCode != null) ? ship.TrackingCode.ToString() : "";
                    string method = (ship.Method != null) ? ship.Method.ToString() : "";
                    if (!orderDto.InvoiceNumber.Equals("") && !orderDto.InvoiceNumber.Equals("0"))
                    {
                        if (!method.Equals(""))
                        {
                            if (method.Contains("UPS"))
                            {
                                orderDto.UpsUspsService = method.Replace("UPS -", "").Trim();
                                carrierType             = CarrierType.Ups;
                            }
                            else
                            {
                                string upsResult = "";
                                try
                                {
                                    upsResult = GetAllUpsServices().SingleOrDefault(s => s.Contains(method)).Trim();
                                }
                                catch (Exception)
                                {
                                    upsResult = "";
                                }
                                if (!string.IsNullOrEmpty(upsResult))
                                {
                                    orderDto.UpsUspsService = method.Replace("UPS -", "");
                                    carrierType             = CarrierType.Ups;
                                }
                                else
                                {
                                    if (method.Contains("USPS"))
                                    {
                                        orderDto.UpsUspsService = method;
                                        carrierType             = CarrierType.Usps;
                                    }
                                    else
                                    {
                                        string uspsResult = "";
                                        try
                                        {
                                            uspsResult = GetAllUspsServices().SingleOrDefault(s => s.Contains(method));
                                        }
                                        catch (Exception)
                                        {
                                            uspsResult = "";
                                        }
                                        if (!string.IsNullOrEmpty(uspsResult))
                                        {
                                            orderDto.UpsUspsService = method;
                                            carrierType             = CarrierType.Usps;
                                        }
                                        else
                                        {
                                            orderDto.UpsUspsService = "Ground";
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            orderDto.UpsUspsService = "Ground";
                        }
                        order newOrder = new order
                        {
                            address        = orderDto.Address,
                            address2       = orderDto.Address2,
                            city           = orderDto.City,
                            company        = orderDto.Company,
                            country        = orderDto.Country,
                            customerid     = orderDto.CustomerId,
                            date_created   = DateTime.Now,
                            date_modifed   = DateTime.Now,
                            email          = orderDto.Email,
                            email_flag     = orderDto.EmailFlag,
                            orderId        = orderDto.OrderId,
                            storeId        = orderDto.StoreId,
                            invoice_number = orderDto.InvoiceNumber,
                            name           = orderDto.Name,
                            tracking_code  = orderDto.TrackingCode,
                            phone          = orderDto.Phone,
                            ups_service    = orderDto.UpsUspsService,
                            state          = orderDto.State
                        };
                        context.orders.AddObject(newOrder);
                        context.SaveChanges();
                        ordersRepositoryDbMethods.InsertOrderDataToRepository(orderDto);
                    }
                }
            }
            catch (InvalidOperationException exc)
            {
                return(false);
            }
            catch (ArgumentNullException exc)
            {
                return(false);
            }
            catch (NullReferenceException exc)
            {
                return(false);
            }
            catch (OptimisticConcurrencyException exc)
            {
                return(false);
            }
            catch (UpdateException exc)
            {
                return(false);
            }
            finally
            {
                context.Dispose();
            }
            return(true);
        }