private StoresDocument GetDataStoresFile(string directory) { StoresDocument storesDocument = null; foreach (string currentFile in Directory.GetFiles(directory)) { if(currentFile.Contains(@"\Stores")) { XDocument xmlDoc = XDocument.Load(currentFile); string chainStoresName = xmlDoc.Element("Root").Element("ChainName").Value.ToString(); if(chainStoresName != null) { storesDocument = new StoresDocument(chainStoresName); var stores = xmlDoc.Descendants("Store").ToList(); if(stores.Count == 0) { stores = xmlDoc.Descendants("store").ToList(); } foreach (XElement xmlStore in stores) { string id = xmlStore.Element("StoreId").Value.ToString(); string name = xmlStore.Element("StoreName").Value.ToString(); storesDocument.AddStore(id, name); } return storesDocument; } else { return null; } } } return null; }
private Store AddStoreToDB(XDocument xmlDoc, StoresDocument storesDocument) { Store store = null; if(storesDocument != null) { string storeId = xmlDoc.Element("Root").Element("StoreId").Value.ToString(); string name = storesDocument.Stores[storeId]; if (name != null) { store = new Store(name); store.ChainStoreName = storesDocument.ChainStoresName; PriceCompareDataAccess dataAccess = new PriceCompareDataAccess(); dataAccess.AddStore(store); } } return store; }