using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Weee.Models.ExtensionMethods { public static class PowerUsageExtension { public static decimal GetTotalPowerPeak(this ICollection powerUsages) { decimal totalPowerPeak = 0; foreach (var powerUsage in powerUsages) { if (powerUsage.Peak.HasValue) totalPowerPeak += powerUsage.Peak.Value; } return totalPowerPeak; } public static decimal GetTotalPowerHalfPeak(this ICollection powerUsages) { decimal totalPowerHalfPeak = 0; foreach (var powerUsage in powerUsages) { if (powerUsage.HalfPeak.HasValue) totalPowerHalfPeak += powerUsage.HalfPeak.Value; } return totalPowerHalfPeak; } public static decimal GetTotalPowerSaturdayHalfPeak(this ICollection powerUsages) { decimal totalPowerSaturdayHalfPeak = 0; foreach (var powerUsage in powerUsages) { if (powerUsage.SaturdayHalfPeak.HasValue) totalPowerSaturdayHalfPeak += powerUsage.SaturdayHalfPeak.Value; } return totalPowerSaturdayHalfPeak; } public static decimal GetTotalPowerOffPeak(this ICollection powerUsages) { decimal totalPowerOffPeak = 0; foreach (var powerUsage in powerUsages) { if (powerUsage.OffPeak.HasValue) totalPowerOffPeak += powerUsage.OffPeak.Value; } return totalPowerOffPeak; } public static decimal GetTotalPowerUsage(this ICollection powerUsages) { return powerUsages.GetTotalPowerPeak() + powerUsages.GetTotalPowerHalfPeak() + powerUsages.GetTotalPowerSaturdayHalfPeak() + powerUsages.GetTotalPowerOffPeak(); } } }