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;
        }
    }
}
