Bearbeitung von Fragen
This commit is contained in:
28
MultipleChoiceTrainer/Validation/NotNullOrEmptyAttribute.cs
Normal file
28
MultipleChoiceTrainer/Validation/NotNullOrEmptyAttribute.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MultipleChoiceTrainer.Validation
|
||||
{
|
||||
public class NotNullOrEmptyAttribute : ValidationAttribute
|
||||
{
|
||||
public NotNullOrEmptyAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
if (value == null)
|
||||
return new ValidationResult($"{validationContext.DisplayName} darf nicht leer sein!");
|
||||
|
||||
if (string.IsNullOrEmpty(value.ToString()) || string.IsNullOrWhiteSpace(value.ToString()))
|
||||
{
|
||||
return new ValidationResult($"{validationContext.DisplayName} darf nicht leer sein!");
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user