private static void AddRate(int productId, double productRate, RxRates rates, RasterGridPrescription prescription, UnitOfMeasure uom) { RxProductLookup rxProductLookup; if (prescription.RxProductLookups.Any(x => x.ProductId == productId)) rxProductLookup = prescription.RxProductLookups.Single(x => x.ProductId == productId); else { rxProductLookup = new RxProductLookup { ProductId = productId, UnitOfMeasure = uom }; prescription.RxProductLookups.Add(rxProductLookup); } var rxRate = new RxRate { Rate = productRate, RxProductLookupId = rxProductLookup.Id.ReferenceId, }; rates.RxRate.Add(rxRate); }
private List<RxRates> LoadRatesFromProducts(GridDescriptor gridDescriptor, List<int> productIds, RasterGridPrescription prescription) { var rates = new List<RxRates>(); foreach (var productRates in gridDescriptor.ProductRates) { var rate = new RxRates { RxRate = new List<RxRate>() }; for (int productIndex = 0; productIndex < productRates.Count; productIndex++) { var adaptProductId = productIds[productIndex]; UnitOfMeasure uom = null; AddRate(adaptProductId, productRates[productIndex], rate, prescription, uom); } rates.Add(rate); } return rates; }
private static List<RxRates> LoadRatesFromTreatmentZones(GridDescriptor gridDescriptor, Dictionary<int, TreatmentZone> treatmentZones, List<int> productIds, RasterGridPrescription prescription) { var rates = new List<RxRates>(); foreach (var treatmentZoneId in gridDescriptor.TreatmentZones) { var treatmentZone = treatmentZones.FindById(treatmentZoneId); if (treatmentZone == null) return null; var rate = new RxRates { RxRate = new List<RxRate>() }; for (int i = 0; i < treatmentZone.Variables.Count; i++) { var dataVariable = treatmentZone.Variables[i]; AddRate(productIds[i], dataVariable.Value, rate, prescription, treatmentZone.Variables[i].IsoUnit.ToAdaptUnit()); } rates.Add(rate); } return rates; }