/// <summary> /// Looks up unit, converts and loads representation /// </summary> /// <param name="n"></param> /// <param name="ddi"></param> /// <param name="mapper"></param> /// <returns></returns> /// public static NumericRepresentationValue AsNumericRepresentationValue(this int n, int ddi, RepresentationMapper mapper, UnitOfMeasure userUnitOfMeasure = null) { //RepresentationValue NumericRepresentationValue returnValue = new ApplicationDataModel.Representations.NumericRepresentationValue(); //Representation returnValue.Representation = mapper.Map(ddi) as NumericRepresentation; //Value double convertedValue = (double)n; UnitOfMeasure uom = null; ISOUnit isoUnit = UnitFactory.Instance.GetUnitByDDI(ddi); if (isoUnit != null) { convertedValue = isoUnit.ConvertFromIsoUnit(convertedValue); uom = isoUnit.ToAdaptUnit(); } returnValue.Value = new ApplicationDataModel.Representations.NumericValue(uom, convertedValue); //User UOM if (userUnitOfMeasure != null) { returnValue.UserProvidedUnitOfMeasure = userUnitOfMeasure; } return(returnValue); }
private void ExportProductRelation(List <ISOProduct> isoProducts, string adaptDescription, ApplicationDataModel.Representations.NumericRepresentationValue quantity, ISOProduct targetMixProduct) { ISOProduct componentProduct = isoProducts.FirstOrDefault(p => p.ProductDesignator == adaptDescription); //Matches on name; assumes all ingredients are also products if (componentProduct != null) { //Create PRNs if we can match to pre-existing products ISOProductRelation relation = new ISOProductRelation(); relation.ProductIdRef = componentProduct.ProductId; relation.QuantityValue = quantity.AsIntViaMappedDDI(RepresentationMapper); targetMixProduct.ProductRelations.Add(relation); } }