public List <Error> Validate(SignUpUserArgs args) { var errors = new List <Error>(); if (string.IsNullOrEmpty(args.Email)) { errors.Add(Error.With(nameof(args.Email), ErrorCodes.Required)); } else if (args.Email.Length > MaximumNumberOfCharacters) { errors.Add(Error.With(nameof(args.Email), ErrorCodes.InvalidLength)); } else if (IsNotValidEmail(args.Email)) { errors.Add(Error.With(nameof(args.Email), ErrorCodes.InvalidFormat)); } if (string.IsNullOrEmpty(args.Password)) { errors.Add(Error.With(nameof(args.Password), ErrorCodes.Required)); } else if (args.Password.Length > MaximumNumberOfCharacters) { errors.Add(Error.With(nameof(args.Password), ErrorCodes.InvalidLength)); } return(errors); }
public ServiceExecutionResult SignUp(SignUpUserArgs args) { var errors = validator.Validate(args); if (errors.Any()) { return(ServiceExecutionResult.WithErrors(errors)); } var user = new User(args.Email, args.Password); saveUserRepository.Save(user); return(ServiceExecutionResult.WithSucess()); }