/// <summary> /// Return all subactivities (level 2) that fullfill search criteria. /// If activityCodes are null, all activities will be returned. If activityCodes is empty no activities will be returned. /// Notice that this will include one subactivity "Not specified on this level" for each activity, even if the activity do not have any subactivities at all! /// </summary> public static IEnumerable <ActivityTreeListRow> GetSubActivities(PollutantTransfersSearchFilter filter, List <string> activityCodes) { if (activityCodes != null && activityCodes.Count() == 0) { return(new List <ActivityTreeListRow>()); } DataClassesPollutantTransferDataContext db = getPollutantTransferDataContext(); Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter); //add activities to expression if (activityCodes != null) { ParameterExpression param = lambda.Parameters[0]; Expression activityExp = LinqExpressionBuilder.GetInExpr(param, "IAActivityCode", activityCodes); Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, activityExp); lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param); } //find data for sub-activity level, this level never has children. IEnumerable <ActivityTreeListRow> subactivities = db.POLLUTANTTRANSFERs.Where(lambda) .GroupBy(p => new { SectorCode = p.IASectorCode, ActivityCode = p.IAActivityCode, SubActivityCode = p.IASubActivityCode, PollutantCode = p.PollutantCode }) .Select(x => new ActivityTreeListRow( x.Key.SectorCode, x.Key.ActivityCode, !x.Key.SubActivityCode.Equals(null) ? x.Key.SubActivityCode : ActivityTreeListRow.CODE_UNSPECIFIED, x.Key.PollutantCode, x.Count(), x.Sum(p => p.Quantity), false)); return(subactivities); }
/// <summary> /// return all activities (level 1) that fullfill search criteria within the sectorCodes given. /// If sectorCodes are null, all activities will be returned. If sectorCodes is empty no activities will be returned. /// </summary> public static IEnumerable <ActivityTreeListRow> GetActivities(PollutantTransfersSearchFilter filter, List <string> sectorCodes) { if (sectorCodes != null && sectorCodes.Count() == 0) { return(new List <ActivityTreeListRow>()); } DataClassesPollutantTransferDataContext db = getPollutantTransferDataContext(); Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter); if (sectorCodes != null) { ParameterExpression param = lambda.Parameters[0]; Expression sectorExp = LinqExpressionBuilder.GetInExpr(param, "IASectorCode", sectorCodes); Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, sectorExp); lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param); } //find data for activity level IEnumerable <ActivityTreeListRow> activities = db.POLLUTANTTRANSFERs.Where(lambda) .GroupBy(p => new { SectorCode = p.IASectorCode, ActivityCode = p.IAActivityCode, PollutantCode = p.PollutantCode }) .Select(x => new ActivityTreeListRow( x.Key.SectorCode, x.Key.ActivityCode, null, x.Key.PollutantCode, x.Count(), x.Sum(p => p.Quantity), x.First(p => !p.IASubActivityCode.Equals(null)) != null)); return(activities); }
/// <summary> /// Return all NACE activities within the ids given /// </summary> public static IEnumerable <LOV_NACEACTIVITY> GetNaceActivities(List <int> lovNaceActivityIds) { ParameterExpression param = Expression.Parameter(typeof(LOV_NACEACTIVITY), "s"); Expression exp = LinqExpressionBuilder.GetInExpr(param, "LOV_NACEActivityID", lovNaceActivityIds); Expression <Func <LOV_NACEACTIVITY, bool> > lambda = Expression.Lambda <Func <LOV_NACEACTIVITY, bool> >(exp, param); IEnumerable <LOV_NACEACTIVITY> result = getLovNaceActivityCache().AsQueryable <LOV_NACEACTIVITY>().Where(lambda); return(result); }
/// <summary> /// Return all AnnexI activities within the ids given /// </summary> public static IEnumerable <LOV_ANNEXIACTIVITY> GetAnnexIActivities(List <int> lovAnnexIActivityIds) { if (lovAnnexIActivityIds.Count() > 0) { ParameterExpression param = Expression.Parameter(typeof(LOV_ANNEXIACTIVITY), "s"); Expression exp = LinqExpressionBuilder.GetInExpr(param, "LOV_AnnexIActivityID", lovAnnexIActivityIds); Expression <Func <LOV_ANNEXIACTIVITY, bool> > lambda = Expression.Lambda <Func <LOV_ANNEXIACTIVITY, bool> >(exp, param); IEnumerable <LOV_ANNEXIACTIVITY> result = getLovAnnexIActivityCache().AsQueryable <LOV_ANNEXIACTIVITY>().Where(lambda); return(result); } else { return(new List <LOV_ANNEXIACTIVITY>()); } }
///<summary> ///Return all subareas (level 1) that fullfill search criteria. ///If countryCodes are null, all subareas will be returned. If countryCodes is empty no subareas will be returned. ///</summary> public static IEnumerable <AreaTreeListRow> GetSubAreas(PollutantTransfersSearchFilter filter, List <string> countryCodes) { if (countryCodes != null && countryCodes.Count() == 0) { return(new List <AreaTreeListRow>()); } DataClassesPollutantTransferDataContext db = getPollutantTransferDataContext(); Expression <Func <POLLUTANTTRANSFER, bool> > lambda = getActivityAreaLambda(filter); //add countries to expression if (countryCodes != null) { ParameterExpression param = lambda.Parameters[0]; Expression countryExp = LinqExpressionBuilder.GetInExpr(param, "CountryCode", countryCodes); Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, countryExp); lambda = Expression.Lambda <Func <POLLUTANTTRANSFER, bool> >(exp, param); } //find data for sub-activity level, this level never has children. AreaFilter.RegionType regionType = filter.AreaFilter.TypeRegion; bool isRbd = AreaFilter.RegionType.RiverBasinDistrict.Equals(regionType); IEnumerable <AreaTreeListRow> subareas = db.POLLUTANTTRANSFERs.Where(lambda) .GroupBy(p => new { CountryCode = p.CountryCode, SubAreaCode = isRbd ? p.RiverBasinDistrictCode : p.NUTSLevel2RegionCode, PollutantCode = p.PollutantCode }) .Select(x => new AreaTreeListRow( x.Key.CountryCode, !x.Key.SubAreaCode.Equals(null) ? x.Key.SubAreaCode : AreaTreeListRow.CODE_UNKNOWN, regionType, x.Key.PollutantCode, x.Count(), x.Sum(p => p.Quantity), false)); return(subareas); }