From ffcb6c463b472581efdcfd30a8edd282d1fdfed6 Mon Sep 17 00:00:00 2001
From: Dan <daniel2.lorych@live.uwe.ac.uk>
Date: Mon, 2 May 2022 11:33:43 +0100
Subject: [PATCH] Update the configurator to accept two roofs

---
 Helios/Models/ConfiguratorInput.cs            |  2 +-
 Helios/Source/ConfiguratorService.cs          | 35 ++++++++++---------
 .../Configurator/ConfiguratorResult.cshtml    |  3 ++
 Helios/Views/Configurator/Index.cshtml        | 34 ++++++++++++++----
 4 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/Helios/Models/ConfiguratorInput.cs b/Helios/Models/ConfiguratorInput.cs
index bc10b3a..519758c 100644
--- a/Helios/Models/ConfiguratorInput.cs
+++ b/Helios/Models/ConfiguratorInput.cs
@@ -5,7 +5,7 @@ namespace Helios.Models
 {
 	public class ConfiguratorInput
 	{
-        public Roof Roof { get; set; }
+        public List<Roof> Roofs { get; set; }
 
 		[DisplayName("Energy usage in KwH?")]
 		public int PowerRequired { get; set; }
diff --git a/Helios/Source/ConfiguratorService.cs b/Helios/Source/ConfiguratorService.cs
index 27d5ca4..ce47bfa 100644
--- a/Helios/Source/ConfiguratorService.cs
+++ b/Helios/Source/ConfiguratorService.cs
@@ -24,22 +24,25 @@ namespace Helios.Source
 
 			foreach (SolarPanel panel in _solarPanels)
 			{
-				ConfiguratorResult result = new ConfiguratorResult();
-
-				int summerElevationAngle = input.Roof.GetElevationAngle(_maxElevation.SummerElevation);
-				int winterElevationAngle = input.Roof.GetElevationAngle(_maxElevation.WinterElevation);
-
-				result.RoofArea = input.Roof.Area;
-				result.RoofAngle = input.Roof.Elevation;
-				result.PanelEfficiency = panel.Efficiency * 100;
-				result.InstallationCost = panel.GetInstallationCost(input.Roof.Area);
-				result.PowerGeneratedSummer = Math.Round(panel.GetPowerOutput(input.Roof.Area, summerElevationAngle), 2);
-				result.PowerGeneratedWinter = Math.Round(panel.GetPowerOutput(input.Roof.Area, winterElevationAngle), 2);
-				result.GeneratesRequiredPower = GeneratesRequiredPower(input.PowerRequired, result.PowerGeneratedWinter);
-				result.ExceedsMaximumPower = ExceedsPowerLimit(input.MaximumPower, result.PowerGeneratedWinter);
-				result.WithinBudget = WithinBudget(input.Budget, result.InstallationCost);
-					
-				results.Add(result);
+				foreach (Roof roof in input.Roofs)
+                {
+					ConfiguratorResult result = new ConfiguratorResult();
+
+					int summerElevationAngle = roof.GetElevationAngle(_maxElevation.SummerElevation);
+					int winterElevationAngle = roof.GetElevationAngle(_maxElevation.WinterElevation);
+
+					result.RoofArea = roof.Area;
+					result.RoofAngle = roof.Elevation;
+					result.PanelEfficiency = panel.Efficiency * 100;
+					result.InstallationCost = panel.GetInstallationCost(roof.Area);
+					result.PowerGeneratedSummer = Math.Round(panel.GetPowerOutput(roof.Area, summerElevationAngle), 2);
+					result.PowerGeneratedWinter = Math.Round(panel.GetPowerOutput(roof.Area, winterElevationAngle), 2);
+					result.GeneratesRequiredPower = GeneratesRequiredPower(input.PowerRequired, result.PowerGeneratedWinter);
+					result.ExceedsMaximumPower = ExceedsPowerLimit(input.MaximumPower, result.PowerGeneratedWinter);
+					result.WithinBudget = WithinBudget(input.Budget, result.InstallationCost);
+
+					results.Add(result);
+				}
 			}			
 
 			return results;
diff --git a/Helios/Views/Configurator/ConfiguratorResult.cshtml b/Helios/Views/Configurator/ConfiguratorResult.cshtml
index 74267a6..8ca3354 100644
--- a/Helios/Views/Configurator/ConfiguratorResult.cshtml
+++ b/Helios/Views/Configurator/ConfiguratorResult.cshtml
@@ -4,6 +4,9 @@
     ViewData["Title"] = "Configuration Results";
 }
 
+<h4>Configurator Results</h4>
+<hr />
+
 <table class="table">
     <tr>
         <th>
diff --git a/Helios/Views/Configurator/Index.cshtml b/Helios/Views/Configurator/Index.cshtml
index e699b9e..0e2ed14 100644
--- a/Helios/Views/Configurator/Index.cshtml
+++ b/Helios/Views/Configurator/Index.cshtml
@@ -12,22 +12,44 @@
 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" })
 
+    <h5>Roof #1</h5>
+
     <div class="form-group">
-        @Html.LabelFor(model => model.Roof.Area, htmlAttributes: new { @class = "control-label col-md-2" })
+        @Html.LabelFor(model => model.Roofs[0].Area, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
-            @Html.EditorFor(model => model.Roof.Area, new { htmlAttributes = new { @class = "form-control" } })
-            @Html.ValidationMessageFor(model => model.Roof.Area, "", new { @class = "text-danger" })
+            @Html.EditorFor(model => model.Roofs[0].Area, new { htmlAttributes = new { @class = "form-control" } })
+            @Html.ValidationMessageFor(model => model.Roofs[0].Area, "", new { @class = "text-danger" })
         </div>
     </div>
 
     <div class="form-group">
-        @Html.LabelFor(model => model.Roof.Elevation, htmlAttributes: new { @class = "control-label col-md-2" })
+        @Html.LabelFor(model => model.Roofs[0].Elevation, htmlAttributes: new { @class = "control-label col-md-2" })
+        <div class="col-md-10">
+            @Html.EditorFor(model => model.Roofs[0].Elevation, new { htmlAttributes = new { @class = "form-control" } })
+            @Html.ValidationMessageFor(model => model.Roofs[0].Elevation, "", new { @class = "text-danger" })
+        </div>
+    </div>
+
+    <h5>Roof #2</h5>
+
+    <div class="form-group">
+        @Html.LabelFor(model => model.Roofs[1].Area, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
-            @Html.EditorFor(model => model.Roof.Elevation, new { htmlAttributes = new { @class = "form-control" } })
-            @Html.ValidationMessageFor(model => model.Roof.Elevation, "", new { @class = "text-danger" })
+            @Html.EditorFor(model => model.Roofs[1].Area, new { htmlAttributes = new { @class = "form-control" } })
+            @Html.ValidationMessageFor(model => model.Roofs[1].Area, "", new { @class = "text-danger" })
         </div>
     </div>
 
+    <div class="form-group">
+        @Html.LabelFor(model => model.Roofs[1].Elevation, htmlAttributes: new { @class = "control-label col-md-2" })
+        <div class="col-md-10">
+            @Html.EditorFor(model => model.Roofs[1].Elevation, new { htmlAttributes = new { @class = "form-control" } })
+            @Html.ValidationMessageFor(model => model.Roofs[1].Elevation, "", new { @class = "text-danger" })
+        </div>
+    </div>
+
+    <h5>Energy Information</h5>
+
     <div class="form-group">
         @Html.LabelFor(model => model.PowerRequired, htmlAttributes: new { @class = "control-label col-md-2" })
         <div class="col-md-10">
-- 
GitLab