Example #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (DefaultPermissions.Any(x => x.IsNullOrWhiteSpace()))
            {
                yield return(new ValidationResult("A permission value cannot be null or empty", new[] { "Permissions" }));
            }

            foreach (var assignedPermission in AssignedPermissions)
            {
                foreach (var permission in assignedPermission.Value)
                {
                    if (permission.IsNullOrWhiteSpace())
                    {
                        yield return(new ValidationResult("A permission value cannot be null or empty", new[] { "AssignedPermissions" }));
                    }
                }
            }
        }
Example #2
0
    public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
    {
        if (DefaultPermissions?.Any(x => x.IsNullOrWhiteSpace()) ?? false)
        {
            yield return(new ValidationResult("A permission value cannot be null or empty", new[] { "Permissions" }));
        }

        if (AssignedPermissions is not null)
        {
            foreach (KeyValuePair <int, IEnumerable <string> > assignedPermission in AssignedPermissions)
            {
                foreach (var permission in assignedPermission.Value)
                {
                    if (permission.IsNullOrWhiteSpace())
                    {
                        yield return(new ValidationResult(
                                         "A permission value cannot be null or empty",
                                         new[] { "AssignedPermissions" }));
                    }
                }
            }
        }
    }