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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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); }
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); }
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(); } }
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(); } }