Browse Source

验证必填项目添加 IsNullableType 判断

集成Redis
马昊 2 years ago
parent
commit
c2ba79af41
  1. 28
      be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs

28
be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs

@ -233,7 +233,6 @@ public class ClosedXmlExportImportService : IExportImportService
if (property != null) if (property != null)
{ {
var propertyType = property.PropertyType; var propertyType = property.PropertyType;
if (value.ToString() != "") if (value.ToString() != "")
{ {
if (propertyType.IsEnum) if (propertyType.IsEnum)
@ -264,22 +263,25 @@ public class ClosedXmlExportImportService : IExportImportService
} }
else else
{ {
if (propertyType.IsEnum || propertyType.Name == nameof(Boolean) || propertyType.IsValueType) if (propertyType.IsNullableType() == false)
{ {
/* if (propertyType.IsEnum || propertyType.Name == nameof(Boolean) || propertyType.IsValueType)
* bool Required
* Required NULL
*/
var isHasRequiredAttribute = property.HasAttribute<RequiredAttribute>();
if (isHasRequiredAttribute == true)
{ {
var requiredAttribute = property.GetCustomAttribute<RequiredAttribute>(); /*
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name ?? headerName; * bool Required
string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName); * Required NULL
validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" })); */
var isHasRequiredAttribute = property.HasAttribute<RequiredAttribute>();
if (isHasRequiredAttribute == true)
{
var requiredAttribute = property.GetCustomAttribute<RequiredAttribute>();
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name ?? headerName;
string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName);
validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" }));
}
} }
} }
} }
} }
} }
result.Add(model, validationRresults); result.Add(model, validationRresults);

Loading…
Cancel
Save