Пример #1
0
        public StoreDto GetStoreById(int id)
        {
            StoreDto dto     = null;
            var      context = new orderstatusEntities();

            try
            {
                stores_data storeContext = context.stores_data.Where(x => x.id == id).SingleOrDefault();
                if (storeContext != null)
                {
                    dto          = new StoreDto();
                    dto.Id       = storeContext.id;
                    dto.Url      = storeContext.url;
                    dto.Name     = storeContext.name;
                    dto.ApiKey   = storeContext.api_key;
                    dto.Interval = int.Parse(storeContext.interval.ToString());

                    dto.CustomShipmentsDtos = GetCustomShipmentByStoreId(storeContext.id);
                }
                return(dto);
            }
            catch (Exception ex)
            {
                log.Error("Error Exception GetStoreById: " + ex.Message);
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #2
0
        public bool CreateOrdersFromStore(dynamic data, int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                foreach (var orderData in data)
                {
                    if (orderData.InvoiceNumber != null && !orderData.InvoiceNumber.ToString().Equals(""))
                    {
                        OrderDto orderDto = new OrderDto()
                        {
                            OrderId       = (orderData.OrderID != null)?orderData.OrderID.ToString():"",
                            StoreId       = storeId,
                            InvoiceNumber =
                                (orderData.InvoiceNumber != null)
                                                            ? orderData.InvoiceNumber.ToString()
                                                            : "",
                            CustomerId =
                                (orderData.CustomerID != null)
                                                            ? orderData.CustomerID.ToString()
                                                            : "",
                            Email = (orderData.Email != null)
                                                            ? orderData.Email.ToString()
                                                            : "",
                        };
                        foreach (var ship in orderData.Shippinginfo)
                        {
                            CreateShippingInformation(XDocument.Parse(ship.ToString()), orderDto);
                        }
                    }
                }
            }
            catch (InvalidOperationException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return(true);
        }
Пример #3
0
        public bool AddOrderStatusByStoreId(List <string> list, int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                foreach (var statusId in list)
                {
                    order_status_by_store orderStatusByStore = new order_status_by_store();
                    orderStatusByStore.order_status_value = int.Parse(statusId.ToString());
                    orderStatusByStore.storeid            = storeId;
                    orderStatusByStore.date_created       = DateTime.Now;
                    orderStatusByStore.date_modified      = DateTime.Now;
                    orderStatusByStore.is_valid           = 1;
                    context.order_status_by_store.AddObject(orderStatusByStore);
                    context.SaveChanges();
                }
                return(true);
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(false);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(false);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(false);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(false);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(false);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #4
0
        public List <StoreDto> GetAllStores()
        {
            var             data         = new orderstatusEntities();
            List <StoreDto> listOfStores = new List <StoreDto>();

            try {
                var ts     = "";
                var stores = data.stores_data.Where(x => x.isActive == 1).ToList();
                foreach (var store in stores)
                {
                    listOfStores.Add(new StoreDto
                    {
                        Id      = store.id,
                        Name    = store.name,
                        ApiKey  = store.api_key,
                        ApiUser = "",
                        Url     = store.url,
                        LastRun = (DateTime)store.last_run
                    });
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error InvalidOperationException: " + exc.Message);
                return(null);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error ArgumentNullException: " + exc.Message);
                return(null);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error NullReferenceException: " + exc.Message);
                return(null);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error OptimisticConcurrencyException: " + exc.Message);
                return(null);
            }
            catch (UpdateException exc)
            {
                log.Error("Error UpdateException: " + exc.Message);
                return(null);
            }
            finally
            {
                data.Dispose();
            }
            return(listOfStores);
        }
Пример #5
0
        public int AddCustomOrderStatus(string text)
        {
            var context = new orderstatusEntities();

            try
            {
                order_status_values orderst = new order_status_values();
                orderst.text         = text;
                orderst.isPublic     = 0;
                orderst.isActive     = 1;
                orderst.dateCreated  = DateTime.Now;
                orderst.dateModified = DateTime.Now;
                context.order_status_values.AddObject(orderst);
                context.SaveChanges();
                return(orderst.id);
            }
            catch (InvalidOperationException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                log.Error("Error InvalidOperationException AddCustomOrderStatus: " + exc.Message);
                return(0);
            }
            catch (ArgumentNullException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                log.Error("Error ArgumentNullException AddCustomOrderStatus: " + exc.Message);
                return(0);
            }
            catch (NullReferenceException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                log.Error("Error NullReferenceException AddCustomOrderStatus: " + exc.Message);
                return(0);
            }
            catch (OptimisticConcurrencyException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                log.Error("Error OptimisticConcurrencyException AddCustomOrderStatus: " + exc.Message);
                return(0);
            }
            catch (UpdateException exc)
            {
                log.Error("Error UpdateException AddCustomOrderStatus: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #6
0
        public int AddStore(StoreDto store)
        {
            var context = new orderstatusEntities();

            try
            {
                stores_data storeContext = new stores_data();
                storeContext.name     = store.Name;
                storeContext.api_key  = store.ApiKey;
                storeContext.url      = store.Url;
                storeContext.interval = store.Interval;
                storeContext.last_run = DateTime.Now;

                storeContext.dateCreated  = DateTime.Now;
                storeContext.dateModified = DateTime.Now;
                storeContext.isActive     = 1;
                context.stores_data.AddObject(storeContext);
                context.SaveChanges();
                return(storeContext.id);
            }
            catch (InvalidOperationException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (ArgumentNullException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (NullReferenceException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (OptimisticConcurrencyException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (UpdateException exc)
            {
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #7
0
        public OrderStatusDto GetAllOrderStatusById(int id)
        {
            var            context        = new orderstatusEntities();
            OrderStatusDto orderStatusDto = new OrderStatusDto();

            try
            {
                var status = context.order_status_by_store.Where(x => x.id == id && x.is_valid == 1).SingleOrDefault();
                if (status != null)
                {
                    orderStatusDto = new OrderStatusDto
                    {
                        IsPublic = status.order_status_values.isPublic.ToString().Equals("1")?true:false,
                        Text     = status.order_status_values.text
                    };
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error InvalidOperationException GetAllOrderStatusById: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error ArgumentNullException GetAllOrderStatusById: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error NullReferenceException GetAllOrderStatusById: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error OptimisticConcurrencyException GetAllOrderStatusById: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return(orderStatusDto);
        }
Пример #8
0
        public List <OrderStatusDto> GetPublicOrdersStatus()
        {
            orderstatusEntities   data             = new orderstatusEntities();
            List <OrderStatusDto> listOrdersStatus = new List <OrderStatusDto>();

            try
            {
                var orderStatusList = data.order_status_values.Where(x => x.isPublic == 1).ToList();
                foreach (var orderStatus in orderStatusList)
                {
                    listOrdersStatus.Add(new OrderStatusDto()
                    {
                        Id   = orderStatus.id,
                        Text = orderStatus.text
                    });
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error InvalidOperationException GetPublicOrdersStatus: " + exc.Message);
                return(null);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error ArgumentNullException GetPublicOrdersStatus: " + exc.Message);
                return(null);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error NullReferenceException GetPublicOrdersStatus: " + exc.Message);
                return(null);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error OptimisticConcurrencyException GetPublicOrdersStatus: " + exc.Message);
                return(null);
            }
            catch (UpdateException exc)
            {
                log.Error("Error UpdateException GetPublicOrdersStatus: " + exc.Message);
                return(null);
            }
            finally
            {
                data.Dispose();
            }
            return(listOrdersStatus);
        }
Пример #9
0
        public void CreateCustomShipments(List <string> names, int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                foreach (var name in names)
                {
                    custom_shipments customShipments = new custom_shipments();
                    customShipments.name         = name;
                    customShipments.storeId      = storeId;
                    customShipments.dateCreated  = DateTime.Now;
                    customShipments.dateModified = DateTime.Now;
                    customShipments.isActive     = 1;
                    context.custom_shipments.AddObject(customShipments);
                    context.SaveChanges();
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error InvalidOperationException CreateCustomShipments: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error ArgumentNullException CreateCustomShipments: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error NullReferenceException CreateCustomShipments: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error OptimisticConcurrencyException CreateCustomShipments: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #10
0
        public List <string> GetAllOrderStatusTextByStore(int storeId)
        {
            var           context      = new orderstatusEntities();
            List <string> ordersStatus = new List <string>();

            try
            {
                var orderStatus = context.order_status_by_store.Where(x => x.storeid == storeId).ToList();
                foreach (var orderStatusByStore in orderStatus)
                {
                    ordersStatus.Add(orderStatusByStore.order_status_values.text);
                }

                return(ordersStatus);
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }

            return(ordersStatus);
        }
Пример #11
0
        public List <int> GetAllPublicOrderStatusByStore(int storeId)
        {
            var        context   = new orderstatusEntities();
            List <int> listOfIds = new List <int>();

            try
            {
                var orderStatus = context.order_status_by_store.Where(x => x.storeid == storeId && x.is_valid == 1 && x.order_status_values.isPublic == 1).ToList();
                if (orderStatus.Count > 0)
                {
                    foreach (var status in orderStatus)
                    {
                        listOfIds.Add(status.order_status_value);
                    }
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return(listOfIds);
        }
Пример #12
0
        public string  GetNonPublicOrderStatusByStore(int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                string customStatus = "";
                var    orderStatus  =
                    context.order_status_by_store.Where(
                        x => x.storeid == storeId && x.is_valid == 1 && x.order_status_values.isPublic == 0).ToList();
                foreach (var status in orderStatus)
                {
                    customStatus += status.order_status_values.text + ";";
                }
                if (customStatus.Length > 0)
                {
                    customStatus = customStatus.Remove(customStatus.Length - 1);
                }
                return(customStatus);
            }
            catch (InvalidOperationException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return("");
        }
Пример #13
0
        public List <CustomShipmentsDto> GetCustomShipmentByStoreId(int storeId)
        {
            var context = new orderstatusEntities();
            List <CustomShipmentsDto> list = new List <CustomShipmentsDto>();

            try
            {
                var custShip = context.custom_shipments.Where(x => x.storeId == storeId && x.isActive == 1).ToList();
                foreach (var shipmentse in custShip)
                {
                    list.Add(new CustomShipmentsDto {
                        Id = shipmentse.id, Name = shipmentse.name
                    });
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error InvalidOperationException GetCustomShipmentByStoreId: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error ArgumentNullException GetCustomShipmentByStoreId: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error NullReferenceException GetCustomShipmentByStoreId: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error OptimisticConcurrencyException GetCustomShipmentByStoreId: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                log.Error("Error UpdateException GetCustomShipmentByStoreId: " + exc.Message);
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return(list);
        }
Пример #14
0
        public string GetOrderStatusText(int statusId)
        {
            var context = new orderstatusEntities();

            try
            {
                var status = context.order_status_by_store.Where(x => x.id == statusId && x.is_valid == 1).SingleOrDefault();
                if (status != null)
                {
                    return(status.order_status_values.text);
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
            return("");
        }
Пример #15
0
        public bool CheckIfOrderExist(string invoiceNumber)
        {
            orderstatusEntities data = new orderstatusEntities();

            try
            {
                var order = data.orders.Where(x => x.invoice_number == invoiceNumber).SingleOrDefault();
                if (order != null)
                {
                    return(true);
                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                return(false);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                return(false);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                return(false);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                return(false);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                return(false);
            }
            finally
            {
                data.Dispose();
            }
            return(false);
        }
Пример #16
0
        public void UpdateStoreLastRun(int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                var store = context.stores_data.Where(x => x.id == storeId).SingleOrDefault();
                store.last_run = DateTime.Now;

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                log.Error("Error Exception UpdateStoreLastRun: " + ex.Message);
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #17
0
        public List <string> GetAllUspsServices()
        {
            List <string> allServices = new List <string>();
            var           context     = new orderstatusEntities();

            try
            {
                var services = context.usps_service.ToList();
                foreach (var uspsService in services)
                {
                    allServices.Add(uspsService.service);
                }
            }
            catch (InvalidOperationException exc)
            {
                return(null);
            }
            catch (ArgumentNullException exc)
            {
                return(null);
            }
            catch (NullReferenceException exc)
            {
                return(null);
            }
            catch (OptimisticConcurrencyException exc)
            {
                return(null);
            }
            catch (UpdateException exc)
            {
                return(null);
            }
            finally
            {
                context.Dispose();
            }

            return(allServices);
        }
Пример #18
0
        public List <OrderDto> GetAllOrdersToProcess()
        {
            List <OrderDto> allOrders = new List <OrderDto>();

            try
            {
                orderstatusEntities data = new orderstatusEntities();
                var orders = data.orders.ToList();
                foreach (var order in orders)
                {
                    OrderDto orderDto = new OrderDto();
                    orderDto.Id      = order.id;
                    orderDto.OrderId = order.orderId;
                    allOrders.Add(orderDto);
                }
            }
            catch (InvalidOperationException exc)
            {
                return(null);
            }
            catch (ArgumentNullException exc)
            {
                return(null);
            }
            catch (NullReferenceException exc)
            {
                return(null);
            }
            catch (OptimisticConcurrencyException exc)
            {
                return(null);
            }
            catch (UpdateException exc)
            {
                return(null);
            }

            return(allOrders);
        }
Пример #19
0
        public void UpdateOrderStatusStoreId(int orderStatusId, int storeId)
        {
            var context = new orderstatusEntities();

            try
            {
                //order_status orderst = context..Where(x => x.id == orderStatusId).SingleOrDefault();
                //if (orderst != null)
                //{
                //    orderst.storeid = storeId;
                //    orderst.dateModified = DateTime.Now;
                //    context.SaveChanges();
                //}
            }
            catch (InvalidOperationException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (ArgumentNullException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (NullReferenceException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (OptimisticConcurrencyException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            catch (UpdateException exc)
            {
                AccessConnectionHandler.log.Error(exc);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #20
0
        public bool RemoveStore(int id)
        {
            var context = new orderstatusEntities();

            try
            {
                stores_data storeContext = context.stores_data.Where(x => x.id == id).SingleOrDefault();
                if (storeContext != null)
                {
                    storeContext.isActive = 0;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error("Error Exception: " + ex.Message);
                return(false);
            }
            finally
            {
                context.Dispose();
            }
            return(true);
        }
Пример #21
0
        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);
        }
Пример #22
0
        public bool UpdateOrderByInvoice(string invoiceNumber, string trackingNumber)
        {
            var context = new orderstatusEntities();

            try
            {
                var order = context.orders.Where(x => x.invoice_number == invoiceNumber).OrderByDescending(x => x.date_created).FirstOrDefault();
                if (order != null)
                {
                    var store = context.stores_data.FirstOrDefault(x => x.id == order.storeId);
                    if (store != null)
                    {
                        cartAPI api     = new cartAPI();
                        var     results = api.getOrderStatus(store.url, store.api_key, order.invoice_number, "");
                        if (results != null && results.ChildNodes[2] != null && !results.ChildNodes[2].InnerText.ToString().Equals("Shipped") && !results.ChildNodes[2].InnerText.ToString().Equals("Complete"))
                        {
                            var result = api.updateOrderShipment(store.url, store.api_key, order.invoice_number, "",
                                                                 trackingNumber, DateTime.Now.ToShortDateString(), "");

                            if (result.InnerText.Equals("OK"))
                            {
                                var resultStatus = api.updateOrderStatus(store.url, store.api_key, order.invoice_number, "Shipped", "");
                                using (StreamWriter writer = File.AppendText(ConfigurationManager.AppSettings["logPathFile"]))
                                {
                                    writer.WriteLine("Order Invoice: " + order.invoice_number + " updated from " + results.ChildNodes[2].InnerText.ToString() + " to Shipped");
                                }

                                var asr = resultStatus;
                            }
                        }
                    }
                    order.tracking_code = trackingNumber;
                    order.date_modifed  = DateTime.Now;
                    context.SaveChanges();
                }

                return(true);
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error UpdateOrderByInvoice: " + exc.InnerException.Message);
                return(false);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error UpdateOrderByInvoice: " + exc.InnerException.Message);
                return(false);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error UpdateOrderByInvoice: " + exc.InnerException.Message);
                return(false);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error UpdateOrderByInvoice: " + exc.InnerException.Message);
                return(false);
            }
            catch (UpdateException exc)
            {
                log.Error("Error UpdateOrderByInvoice: " + exc.InnerException.Message);
                return(false);
            }
            finally
            {
                context.Dispose();
            }
        }
Пример #23
0
        public int EditStore(StoreDto store)
        {
            var context = new orderstatusEntities();

            try
            {
                var storeContext = context.stores_data.Where(x => x.id == store.Id).SingleOrDefault();
                if (storeContext != null)
                {
                    storeContext.name         = store.Name;
                    storeContext.api_key      = store.ApiKey;
                    storeContext.url          = store.Url;
                    storeContext.interval     = store.Interval;
                    storeContext.dateModified = DateTime.Now;
                    storeContext.isActive     = 1;
                    context.SaveChanges();
                }
                var orderStatus = context.order_status_by_store.Where(x => x.storeid == store.Id).ToList();
                foreach (var orderStatusByStore in orderStatus)
                {
                    context.order_status_by_store.DeleteObject(orderStatusByStore);
                    context.SaveChanges();
                }
                var customShips = context.custom_shipments.Where(x => x.storeId == store.Id).ToList();
                foreach (var customShipmentse in customShips)
                {
                    context.custom_shipments.DeleteObject(customShipmentse);
                    context.SaveChanges();
                }
                return(store.Id);
            }
            catch (InvalidOperationException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (ArgumentNullException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (NullReferenceException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            catch (UpdateException exc)
            {
                log.Error("Error: " + exc.Message + " locations" + exc.TargetSite);
                AccessConnectionHandler.log.Error(exc);
                return(0);
            }
            finally
            {
                context.Dispose();
            }
        }