private static void ExctractDataFromFile(XContainer itemsXml, IEnumerable <ItemGeneralData> itemList, IDictionary <int, List <ItemFullData> > itemsFullData) { foreach (var itemGeneralData in itemList) { try { var item = itemsXml.Elements() .Last() .Elements() .First(e => CheckExistance(e.Element("ItemCode")?.Value, itemGeneralData)); AddFullData(itemGeneralData, item, itemsFullData); } catch (InvalidOperationException e) { var item = new ItemFullData { ChainId = "0", ChainName = "Error", ItemCode = "0", ItemId = 0, ItemName = "קובץ שגוי", ItemPrice = "0" }; if (!itemsFullData.ContainsKey(itemGeneralData.ItemId)) { itemsFullData.Add(itemGeneralData.ItemId, new List <ItemFullData> { item }); } else { itemsFullData[itemGeneralData.ItemId].Add(item); } } } }
private static void AddFullData(ItemGeneralData itemGeneralData, XContainer item, IDictionary <int, List <ItemFullData> > itemsFullData) { var itemId = itemGeneralData.ItemId; if (!itemsFullData.ContainsKey(itemId)) { itemsFullData.Add(itemId, new List <ItemFullData>()); } var data = new ItemFullData(); data.ChainId = item.Ancestors().Last().Element("ChainId")?.Value; data.ChainName = GetChainNameById(data.ChainId); data.ItemId = itemId; data.ItemCode = item.Element("ItemCode")?.Value; data.ItemName = item.Element("ItemName")?.Value; data.ItemPrice = item.Element("ItemPrice")?.Value; data.LastUpdateDate = item.Element("PriceUpdateDate")?.Value; data.Quantity = item.Element("Quantity")?.Value; data.StoreId = item.Ancestors().Last()?.Element("StoreId")?.Value; data.UnitOfMeasure = item.Element("UnitOfMeasure")?.Value; itemsFullData[itemId].Add(data); }