private async Task <Result <Identity, ValidationError> > ValidateIdentity(IQueryable <Identity> identities, Identity identity)
        {
            await Task.CompletedTask; // Suppress warning

            if (string.IsNullOrWhiteSpace(identity.Email))
            {
                return(Error <Identity> .Create(MissingEmail));
            }
            return(Ok <ValidationError> .Create(identity));
        }
Beispiel #2
0
        private Result <Person, ValidationError> ValidateIdentity(Person person)
        {
            var errors = Enumerable.Empty <KeyValuePair <string, string[]> >();

            if (string.IsNullOrWhiteSpace(person.FirstName))
            {
                errors = errors.Concat(MissingFirstName);
            }
            if (string.IsNullOrWhiteSpace(person.LastName))
            {
                errors = errors.Concat(MissingLastName);
            }
            if (person.AttendingCourses?.Any() == true && !person.BirthYear.HasValue)
            {
                errors = errors.Concat(MissingAge);
            }

            return(errors.Any() ? Error <Person> .Create(new ValidationError(errors)) : Ok <ValidationError> .Create(person));
        }