示例#1
0
        public static Card Parse(string toParse)
        {
            Card c = null;

            switch (toParse.Length)
            {
            case 2:
                c = new Card(toParse[0].ToString(), toParse[1]);
                break;

            case 3:
                c = new Card(toParse.Substring(0, 2), toParse[2]);
                break;

            default:
                throw new ArgumentException(string.Format("Must be in format VS where V is one of [{0}] and S is one of [{1}]", ValidValues, ValidSuites), nameof(toParse));
            }

            ChainValidation <Card> Validation = CardValidationFactory.GetValidator();

            var validationResult = Validation.Validate(c);

            if (!validationResult.IsValid)
            {
                throw validationResult.Exception;
            }

            return(c);
        }
        private void AuthenticateUser(string email)
        {
            var result = authenticateUserValidation.Validate(new User {
                Email = email
            });

            if (result.IsValid)
            {
                principalHelper.SetAuthenticatedUser(userRepository.Get(email));
                Console.WriteLine("Authentication successful");
            }
            else
            {
                Console.WriteLine(result.Exception.Message);
            }
        }
        private void CreateNewUser(string email, string userName, int tenantId)
        {
            User user = new User {
                Email = email, UserName = userName, TenantId = tenantId
            };
            var result = userCreationValidation.Validate(user);

            if (result.IsValid)
            {
                userRepository.Add(user);
            }
            else
            {
                Console.WriteLine(result.Exception);
            }
        }