private Ingredient LoadProductRelation(XmlNode productRelationNode, ProductMix productMix)
{
var productId = productRelationNode.GetXmlNodeValue("@A");
var productQuantity = productRelationNode.GetXmlNodeValue("@B");
if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(productQuantity))
return null;
long quantity;
if (!long.TryParse(productQuantity, NumberStyles.Integer, CultureInfo.InvariantCulture, out quantity) ||
quantity < 0)
return null;
Product product;
if (_taskDocument.Products.TryGetValue(productId, out product) == false)
return null;
var unit = _taskDocument.UnitsByItemId.FindById(productId);
var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity));
var ingredient = new ActiveIngredient
{
Description = product.Description,
};
var productComponent = new ProductComponent
{
IngredientId = product.Id.ReferenceId,
Quantity = new NumericRepresentationValue(null, numericValue.UnitOfMeasure, numericValue)
};
if (productMix.ProductComponents == null)
productMix.ProductComponents = new List<ProductComponent>();
productMix.ProductComponents.Add(productComponent);
return ingredient;
}