2020-05-27 02:48:44 +01:00
|
|
|
using System;
|
|
|
|
|
using Blazorise;
|
|
|
|
|
|
|
|
|
|
namespace Marechai.Shared
|
|
|
|
|
{
|
|
|
|
|
public static class Validators
|
|
|
|
|
{
|
2020-05-27 05:29:37 +01:00
|
|
|
public static void ValidateString(ValidatorEventArgs e, string message, int maxLength)
|
2020-05-27 02:48:44 +01:00
|
|
|
{
|
|
|
|
|
string item = e.Value as string;
|
|
|
|
|
|
|
|
|
|
if(item?.Length > maxLength)
|
|
|
|
|
{
|
|
|
|
|
e.ErrorText = message;
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
e.Status = string.IsNullOrWhiteSpace(item) ? ValidationStatus.Error : ValidationStatus.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ValidateIntroducedDate(ValidatorEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(!(e.Value is DateTime item) ||
|
|
|
|
|
item.Year < 1900 ||
|
|
|
|
|
item.Date >= DateTime.UtcNow.Date)
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
else
|
|
|
|
|
e.Status = ValidationStatus.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 05:29:37 +01:00
|
|
|
public static void ValidateDouble(ValidatorEventArgs e, double minValue = 0, double maxValue = double.MaxValue)
|
2020-05-27 02:48:44 +01:00
|
|
|
{
|
|
|
|
|
if(!(e.Value is double item) ||
|
2020-05-27 03:48:34 +01:00
|
|
|
item < minValue || item > maxValue)
|
2020-05-27 02:48:44 +01:00
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
else
|
|
|
|
|
e.Status = ValidationStatus.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 05:29:37 +01:00
|
|
|
public static void ValidateInteger(ValidatorEventArgs e, int minValue = 0, int maxValue = int.MaxValue)
|
2020-05-27 02:48:44 +01:00
|
|
|
{
|
|
|
|
|
if(!(e.Value is int item) ||
|
2020-05-27 03:48:34 +01:00
|
|
|
item < minValue || item > maxValue)
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
else
|
|
|
|
|
e.Status = ValidationStatus.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 05:29:37 +01:00
|
|
|
public static void ValidateLong(ValidatorEventArgs e, long minValue = 0, long maxValue = long.MaxValue)
|
2020-05-27 03:48:34 +01:00
|
|
|
{
|
|
|
|
|
if(!(e.Value is long item) ||
|
|
|
|
|
item < minValue || item > maxValue)
|
2020-05-27 02:48:44 +01:00
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
else
|
|
|
|
|
e.Status = ValidationStatus.Success;
|
|
|
|
|
}
|
2020-05-27 05:29:37 +01:00
|
|
|
|
|
|
|
|
public static void ValidateFloat(ValidatorEventArgs e, float minValue = 0, float maxValue = float.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
if(!(e.Value is float item) ||
|
|
|
|
|
item < minValue || item > maxValue)
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
else
|
|
|
|
|
e.Status = ValidationStatus.Success;
|
|
|
|
|
}
|
2020-05-27 02:48:44 +01:00
|
|
|
}
|
|
|
|
|
}
|