private List <price> PricesToDB(FileInfo xmlFile, PriceCompareDBEntitie context) { XDocument doc = XDocument.Load(xmlFile.FullName); List <price> listOfPrices = new List <price>(); long chain_id; long item_code; int store_id; float priceOfItem; foreach (XElement itemElement in doc.Root.Element("Items").Elements("Item")) { long.TryParse(itemElement.Element("ItemCode").Value, out item_code); long.TryParse(doc.Root.Element("ChainId").Value, out chain_id); var existingItem = context.items.FirstOrDefault(i => i.item_code == item_code); if (existingItem != null) { price price = new price(); price.item_code = existingItem.item_code; int.TryParse(doc.Root.Element("StoreId").Value, out store_id); var existingStore = context.stores.FirstOrDefault(s => s.store_id == store_id && s.chain_id == chain_id); price.store_key = existingStore.store_key; float.TryParse(itemElement.Element("ItemPrice").Value, out priceOfItem); price.price1 = priceOfItem; var existingPrice = context.prices.FirstOrDefault(p => p.item_code == price.item_code && p.store_key == price.store_key); if (existingPrice == null) { listOfPrices.Add(price); } } } return(listOfPrices); }
private List <store> StoresToDB(XDocument storesDoc, PriceCompareDBEntitie context, chain chain) { List <store> listOfStores = new List <store>(); XElement StoresElm = storesDoc.Root.Element("SubChains").Element("SubChain").Element("Stores"); int store_id; foreach (var Store in StoresElm.Elements("Store")) { store store = new store(); int.TryParse(Store.Element("StoreId").Value, out store_id); store.store_id = store_id; store.chain_id = chain.chain_id; store.store_type = null; store.store_name = Store.Element("StoreName").Value; store.address = Store.Element("Address").Value; store.city = Store.Element("City").Value; var existingStore = context.stores.FirstOrDefault(s => s.store_id == store.store_id && s.chain_id == store.chain_id); if (existingStore == null) { listOfStores.Add(store); } else { existingStore.chain_id = chain.chain_id; existingStore.store_type = null; existingStore.store_name = Store.Element("StoreName").Value; existingStore.address = Store.Element("Address").Value; existingStore.city = Store.Element("City").Value; } } return(listOfStores); }
private chain ChainToDB(XDocument storesDoc, PriceCompareDBEntitie context) { XElement root = storesDoc.Root; chain chain = new chain(); long chain_id; long.TryParse(root.Element("ChainId").Value, out chain_id); chain.chain_id = chain_id; chain.chain_name = root.Element("ChainName").Value; return(chain); }
private List <item> ItemsToDB(FileInfo xmlFile, PriceCompareDBEntitie context) { XDocument doc = XDocument.Load(xmlFile.FullName); List <item> listOfItems = new List <item>(); long item_code; foreach (XElement itemElement in doc.Root.Element("Items").Elements("Item")) { item item = new item(); long.TryParse(itemElement.Element("ItemCode").Value, out item_code); item.item_code = item_code; item.item_type = itemElement.Element("ItemType").Value; item.item_name = itemElement.Element("ItemName").Value; item.manufacturer_name = itemElement.Element("ManufacturerName").Value; item.manufacturer_item_description = itemElement.Element("ManufacturerItemDescription").Value; item.unit_quantity = itemElement.Element("UnitQty").Value; item.quantity_in_package = itemElement.Element("Quantity").Value; var existingItem = context.items.FirstOrDefault(i => i.item_code == item.item_code); if (existingItem == null) { listOfItems.Add(item); } else { existingItem.item_type = itemElement.Element("ItemType").Value; existingItem.item_name = itemElement.Element("ItemName").Value; existingItem.manufacturer_name = itemElement.Element("ManufacturerName").Value; existingItem.manufacturer_item_description = itemElement.Element("ManufacturerItemDescription").Value; existingItem.unit_quantity = itemElement.Element("UnitQty").Value; existingItem.quantity_in_package = itemElement.Element("Quantity").Value; } } return(listOfItems); }
public DBManager() { _context = new PriceCompareDBEntitie(); }