-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT][NMP-670] Calculations for Solid Fertigation (#696)
* Fixed validation bug * WIP * Added conditional validation to calculate dry fertigation * WIP * To decimal * WIP * WIP * WIP * solubility auto populates * WIP Still need to properly implement conversions * feat: Added solid calculations and units - TODO: unit conversions of amount to dissolve and tank vol - TODO: general clean up and verification --------- Co-authored-by: Dallas Richmond <[email protected]>
- Loading branch information
1 parent
61bdd24
commit 89626bb
Showing
10 changed files
with
501 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Agri.Models.Configuration | ||
{ | ||
public class DryFertilizerSolubility : Versionable | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
public int FertilizerId { get; set; } | ||
public int SolubilityUnitId { get; set; } | ||
public decimal Value { get; set; } | ||
|
||
[JsonIgnore] | ||
[IgnoreDataMember] | ||
public Fertilizer Fertilizer { get; set; } | ||
|
||
[JsonIgnore] | ||
[IgnoreDataMember] | ||
public SolubilityUnit SolubilityUnit { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Agri.Models.Configuration | ||
{ | ||
public class SolubilityUnit : SelectOption | ||
{ | ||
public SolubilityUnit() | ||
{ | ||
DryFertilizerSolubilities = new List<DryFertilizerSolubility>(); | ||
} | ||
|
||
public decimal ConvFactor { get; set; } | ||
|
||
public List<DryFertilizerSolubility> DryFertilizerSolubilities { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/Server/src/SERVERAPI/Attributes/RequiredIfAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
|
||
namespace SERVERAPI.Attributes | ||
{ | ||
public class RequiredIfAttribute : RequiredAttribute | ||
{ | ||
private string PropertyName { get; set; } | ||
private object[] DesiredValues { get; set; } | ||
|
||
public RequiredIfAttribute(string propertyName, params object[] desiredValues) | ||
{ | ||
PropertyName = propertyName; | ||
DesiredValues = desiredValues; | ||
} | ||
|
||
protected override ValidationResult IsValid(object value, ValidationContext context) | ||
{ | ||
object instance = context.ObjectInstance; | ||
Type type = instance.GetType(); | ||
object propertyValue = type.GetProperty(PropertyName).GetValue(instance, null); | ||
|
||
if (DesiredValues.Contains(propertyValue)) | ||
{ | ||
return base.IsValid(value, context); | ||
} | ||
|
||
return ValidationResult.Success; | ||
} | ||
} | ||
} |
Oops, something went wrong.