/// <summary> /// Create a list of UnitConversion entities from elements under units. /// </summary> /// <param name="flow">UnitGroup parent entity</param> /// <param name="refID">unit group referenceToReferenceUnit</param> private List<UnitConversion> CreateUnitConversionList(UnitGroup unitGroup, string refID) { List<UnitConversion> ucList = new List<UnitConversion>(); IEnumerable<XElement> elements = LoadedDocument.Root.Descendants(ElementName("units")).Elements(ElementName("unit")); foreach (XElement el in elements) { UnitConversion uc = new UnitConversion { Unit = (string)el.Element(ElementName("name")), Conversion = (double)el.Element(ElementName("meanValue")), UnitGroupID = unitGroup.UnitGroupID, LongName = (string)el.Element(ElementName("generalComment")) }; if ( el.Attribute("dataSetInternalID").Value == refID) { unitGroup.ReferenceUnit = uc.Unit; } ucList.Add(uc); } return ucList; }
/// <summary> /// Import data from loaded unitgroup file to new UnitGroup entity /// </summary> /// <param name="ilcdDb">Database context wrapper object</param> /// <returns>true iff data was imported</returns> private bool SaveUnitGroup(DbContextWrapper ilcdDb) { bool isSaved = false; string dataSetInternalID = "0"; string uuid = GetCommonUUID(); if (!ilcdDb.IlcdEntityAlreadyExists<UnitGroup>(uuid)) { UnitGroup unitGroup = new UnitGroup(); SaveIlcdEntity(ilcdDb, unitGroup, DataTypeEnum.UnitGroup); unitGroup.Name = GetCommonName(); // Get Reference Flow Property dataSetInternalID = GetElementValue(ElementName("referenceToReferenceUnit")); if (ilcdDb.AddIlcdEntity(unitGroup, uuid)) { ilcdDb.AddEntities<UnitConversion>(CreateUnitConversionList(unitGroup, dataSetInternalID)); isSaved = true; } } return isSaved; }
public void AddUnitGroup(UnitGroup unitGroup) { _DbContext.UnitGroups.Add(unitGroup); _UnitGroupDictionary.Add(unitGroup.UnitGroupUUID, unitGroup.UnitGroupID); }