public static IEnumerable <JupiterIntake> AddDataForNovanaExtraction(IEnumerable <Plant> Plants, DateTime StartDate, DateTime EndDate) { ShapeOutputTables.IntakeCommonDataTable DT2 = new ShapeOutputTables.IntakeCommonDataTable(); ShapeOutputTables.IndvindingerDataTable DT1 = new ShapeOutputTables.IndvindingerDataTable(); ShapeOutputTables.IndvindingerRow CurrentRow; List <JupiterIntake> _intakes = new List <JupiterIntake>(); //Loop the plants foreach (Plant P in Plants) { //Loop the pumping intakes foreach (var PI in P.PumpingIntakes) { JupiterIntake CurrentIntake = PI.Intake as JupiterIntake; CurrentIntake.Data = DT2.NewIntakeCommonRow(); //Read generic data AddCommonDataForNovana(CurrentIntake); DT2.Rows.Add(CurrentIntake.Data); CurrentRow = DT1.NewIndvindingerRow(); //Construct novana id string NovanaID = P.IDNumber + "_" + CurrentIntake.well.ID.Replace(" ", "") + "_" + CurrentIntake.IDNumber; if (P.PumpingIntakes.Count(var => var.Intake.ToString() == CurrentIntake.ToString()) > 1) { NovanaID += "_" + P.PumpingIntakes.IndexOf(PI); } CurrentRow.NOVANAID = NovanaID; CurrentIntake.Data["NOVANAID"] = NovanaID; CurrentRow.PLANTID = P.IDNumber; CurrentRow.PLANTNAME = P.Name; //Get additional data about the plant from the dataset CurrentRow.NYKOMNR = P.NewCommuneNumber; CurrentRow.KOMNR = P.OldCommuneNumber; CurrentRow.ANTUNDERA = P.SubPlants.Count; CurrentRow.ANLUTMX = P.X; CurrentRow.ANLUTMY = P.Y; CurrentRow.VIRKTYP = P.CompanyType; CurrentRow.ACTIVE = P.Active; if (P.SuperiorPlantNumber.HasValue) { CurrentRow.OVERANL = P.SuperiorPlantNumber.Value; } ; if (P.Extractions.Items.Count > 0) { var SelectecExtrations = P.Extractions.Items.Where(var => var.StartTime >= StartDate && var.StartTime <= EndDate); var ActualValue = SelectecExtrations.FirstOrDefault(var => var.StartTime.Year == EndDate.Year); if (SelectecExtrations.Count() > 0) { CurrentRow.MEANINDV = SelectecExtrations.Average(var => var.Value); if (ActualValue != null) { CurrentRow.AKTUELIND = ActualValue.Value; } else { CurrentRow.AKTUELIND = 0; } } } CurrentRow.PERMIT = P.Permit; CurrentRow.ANTINT_A = P.PumpingIntakes.Count; CurrentRow.ANTBOR_A = P.PumpingWells.Count; if (PI.StartNullable.HasValue) { CurrentRow.INTSTDATE = PI.StartNullable.Value; CurrentRow.FRAAAR = GetFraAar(PI.StartNullable.Value); } else { CurrentRow.FRAAAR = 9999; } if (PI.EndNullable.HasValue) { CurrentRow.INTENDDATE = PI.EndNullable.Value; CurrentRow.TILAAR = GetTilAar(PI.EndNullable.Value); } else { CurrentRow.TILAAR = 9999; } DT1.Rows.Add(CurrentRow); _intakes.Add(CurrentIntake); } } //Add a blank string to ensure length of column DT2.Rows[0]["COMMENT"] = " "; DT2.Merge(DT1); return(_intakes); }