using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Weee.Models.ExtensionMethods { public static class SheetDataExtension { public static decimal GetTotalKgCO2e(this ICollection sheetDatas) where T : SheetData { return sheetDatas.Sum(x => x.KgCO2e); } public static void UpdateKgCO2e(this SheetData self, decimal parametervalue) { self.KgCO2e = self.Scalar * parametervalue; } public static decimal GetWeightDistributeKgCO2e(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var weightDistribute = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetDistributeWeight(); return weightDistribute; } public static decimal GetAreaDistributeKgCO2e(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var areaDistribute = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetDistributeArea(); return areaDistribute; } public static decimal GetHourDistributeKgCO2e(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var hourDistribte = sheetDatas.Sum(x => x.KgCO2e) * productLca.GetDistributeHour(); return hourDistribte; } public static decimal GetWeightDistributePercentage(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e(); var weightDistributeProportion = kgCO2Proportion / productLca.GetDistributeWeight(); return weightDistributeProportion * 100; } public static decimal GetAreaDistributePercentage(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e(); var areaDistribteProportion = kgCO2Proportion / productLca.GetDistributeArea(); return areaDistribteProportion * 100; } public static decimal GetHourDistributePercentage(this ICollection sheetDatas, ProductLCA productLca) where T : SheetData { var kgCO2Proportion = sheetDatas.Sum(x => x.KgCO2e) / productLca.GetTotalFabKgCO2e(); var hourDistributeProportion = kgCO2Proportion * productLca.GetDistributeHour(); return hourDistributeProportion * 100; } } }