AgGateway.ADAPT.ISOv4Plugin.Writers.PrescriptionWriter.AddDataVariable C# (CSharp) Method

AddDataVariable() private method

private AddDataVariable ( TreatmentZone treatmentZone, AgGateway.ADAPT.ApplicationDataModel.Representations.NumericRepresentationValue value, string productId, IsoUnit unit ) : void
treatmentZone AgGateway.ADAPT.ISOv4Plugin.Models.TreatmentZone
value AgGateway.ADAPT.ApplicationDataModel.Representations.NumericRepresentationValue
productId string
unit AgGateway.ADAPT.ISOv4Plugin.Models.IsoUnit
return void
        private void AddDataVariable(TreatmentZone treatmentZone, NumericRepresentationValue value, string productId, IsoUnit unit)
        {
            if (value != null && value.Value != null)
            {
                var targetValue = value.Value.Value;

                // Convert input value to Iso unit
                var adaptUnit = unit.ToAdaptUnit();
                UnitOfMeasure userUnit = null;
                if (adaptUnit != null && value.Value.UnitOfMeasure != null &&
                    adaptUnit.Dimension == value.Value.UnitOfMeasure.Dimension)
                {
                    userUnit = value.Value.UnitOfMeasure;
                    targetValue = _unitConverter.Convert(userUnit.ToInternalUom(), adaptUnit.ToInternalUom(), targetValue);
                }

                var dataVariable = new DataVariable
                {
                    ProductId = productId,
                    Value = targetValue,
                    IsoUnit = unit,
                    UserUnit = userUnit
                };

                treatmentZone.Variables.Add(dataVariable);
            }
        }