Reputation: 4016
I need to run some validation to check that an amount is not less than 100 (for example).
The validation is in my code behind and the value will be set in my web.config but I cant figure out I check if the amount entered is less than the value set in the web.config.
The code I had before the change is
decimal amount = 0;
if (amount < 100)
{
modelState.AddModelError("DisinvestmentsAmount", String.Format(Sippcentre.ErrorMessages.Validation.Value_NotLessThan, "100.00"));
}
Below is what I have added in my web.config
<add key="RaiseMimimum" value="100" />
This is the line of code I know i'll need to call my config file
System.Configuration.ConfigurationManager.AppSettings["RaiseMinimum"].ToString();
I'm unsure what I need to replace the following line of code with to do this check
if (amount < 100)
{
Upvotes: 1
Views: 430
Reputation: 4016
fixed by using the below line of code
var SellMaximum = decimal.Parse(System.Configuration.ConfigurationManager.AppSettings["SellMaximum"].ToString());
Upvotes: 0
Reputation: 1503
How about parsing your RaiseMinimum to an integer?
something like this:
string minString = System.Configuration.ConfigurationManager.AppSettings["RaiseMinimum"].ToString();
int minValue = int.Parse(minString);
if (amount < minValue)
{
Edit: When you have decimal numbers, you can also use:
decimal minValue = decimal.Parse(minString);
That's because the number "12.3" (for example) is not an integer.
Upvotes: 3