diff --git a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs index 41596837..9a2b2f1b 100644 --- a/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs +++ b/app/Server/src/SERVERAPI/Controllers/NutrientsController.cs @@ -461,6 +461,21 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) try { + if (fgvm.buttonPressed == "Calculate") + { + if (!ModelState.IsValid) + { + FertigationDetailsSetup(ref fgvm); + return PartialView(fgvm); + } + + // Calculation logic will be implemented here by Adam and the t + // As of now, clear the model state until that ticket is implemented + ModelState.Clear(); + fgvm.btnText = "Add to Field"; + FertigationDetailsSetup(ref fgvm); // go back to the setup, somewhat recursive + return PartialView(fgvm); + } if (fgvm.buttonPressed == "ResetDensity") { ModelState.Clear(); @@ -639,7 +654,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) { if (!ft.Custom) { - if (fgvm.density != _sd.GetLiquidFertilizerDensity(fgvm.selFertOption, fgvm.selDensityUnitOption).Value.ToString("#.##")) + if (fgvm.density != _sd.GetLiquidFertilizerDensity(fgvm.selFertOption ?? 0, fgvm.selDensityUnitOption ?? 0).Value.ToString("#.##")) { fgvm.stdDensity = false; } @@ -650,7 +665,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm) } } - var fertilizerNutrients = _calculateFertilizerNutrients.GetFertilizerNutrients(fgvm.selFertOption, + var fertilizerNutrients = _calculateFertilizerNutrients.GetFertilizerNutrients(fgvm.selFertOption ?? 0, fgvm.fertilizerType, Convert.ToDecimal(fgvm.productRate), Convert.ToInt32(fgvm.selProductRateUnitOption), @@ -743,7 +758,7 @@ private int FertigationInsert(FertigationDetailsViewModel fgvm) NutrientFertilizer nf = new NutrientFertilizer() { fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption), - fertilizerId = fgvm.selFertOption, + fertilizerId = fgvm.selFertOption ?? 0, applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption), applRate = Convert.ToDecimal(fgvm.productRate), applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate), @@ -764,7 +779,7 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm) { NutrientFertilizer nf = _ud.GetFieldNutrientsFertilizer(fgvm.fieldName, fgvm.id.Value); nf.fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption); - nf.fertilizerId = fgvm.selFertOption; + nf.fertilizerId = fgvm.selFertOption ?? 0; nf.applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption); nf.applRate = Convert.ToDecimal(fgvm.productRate); nf.applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate); diff --git a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs index 4dcdcfd6..bff5e23e 100644 --- a/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs +++ b/app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs @@ -16,44 +16,71 @@ public class FertigationDetailsViewModel public string cropName { get; set; } public string buttonPressed { get; set; } public string fieldArea { get; set; } + //fetilizer type [Required(ErrorMessage = "Required")] [Range(1, 9999, ErrorMessage = "Required")] public string selTypOption { get; set; } // the selected fertilizer type - public int selFertOption { get; set; } // the selected + [Required(ErrorMessage = "Required")] + public int? selFertOption { get; set; } // the selected public string fertilizerType { get; set; } public string currUnit { get; set; } public List typOptions { get; set; } public List fertilizers { get; set; } + //fertilizer public List FertigationList { get; set; } [Required(ErrorMessage = "Required")] [Range(1, 9999, ErrorMessage = "Required")] public List fertOptions { get; set; } + //product rate [Required(ErrorMessage = "Required")] [Range(1, 9999, ErrorMessage = "Required")] public string selProductRateUnitOption { get; set; } public string selProductRateUnitOptionText { get; set; } public List productRateUnitOptions { get; set; } + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] public string productRate { get; set; } + //density //density unit - public int selDensityUnitOption { get; set; } + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] + public int? selDensityUnitOption { get; set; } public List densityUnitOptions { get; set; } + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] public string density { get; set; } public bool stdDensity { get; set; } + //injection rate //injection unit + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] public string injectionRate { get; set; } + [Required(ErrorMessage = "Required")] public string selInjectionRateUnitOption { get; set; } + [Required(ErrorMessage = "Required")] public string selInjectionRateUnitOptionText { get; set; } public List injectionRateUnitOptions { get; set; } + //#of fertigations per season + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] public int eventsPerSeason { get; set; } + //fertigation scheduling + [Required(ErrorMessage = "Required")] + public string selFertSchedOption { get; set; } + [Required(ErrorMessage = "Required")] + [Range(1, 9999, ErrorMessage = "Required")] + public int selApplPeriod { get; set; } public List applPeriod { get; set; } + //start date + [Required(ErrorMessage = "Required")] public string applDate { get; set; } public bool manualEntry { get; set; } //calculated diff --git a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml index a4749afb..ee2376bc 100644 --- a/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml +++ b/app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml @@ -17,22 +17,23 @@

Provide Product Details

- - + +
- +
+
@@ -42,14 +43,15 @@ +
-
- +
- + +
@@ -57,10 +59,10 @@
+
-
@@ -72,30 +74,34 @@

Provide Application Details

- +
- + +
- - + + +
- +
+
- + +
@@ -108,7 +114,7 @@
- +