public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            Validator.TryValidateProperty(Title, new ValidationContext(this, null, null)
            {
                MemberName = "Title"
            }, results);
            Validator.TryValidateProperty(EmailAddress, new ValidationContext(this, null, null)
            {
                MemberName = "EmailAddress"
            }, results);
            Validator.TryValidateProperty(Password, new ValidationContext(this, null, null)
            {
                MemberName = "Password"
            }, results);
            Validator.TryValidateProperty(ConfirmPassword, new ValidationContext(this, null, null)
            {
                MemberName = "ConfirmPassword"
            }, results);

            if (!results.Any())
            {
                if (Password != ConfirmPassword)
                {
                    results.Add(new ValidationResult("Password and Confirm Password did not match.", new string[] { "ConfirmPassword" }));
                }

                if (!_specializationService.Exists(SpecializationId))
                {
                    results.Add(new ValidationResult("Specialization does not exist.", new string[] { "SpecializationId" }));
                }

                if (!_personService.Exists(PersonId))
                {
                    results.Add(new ValidationResult("Person does not exist.", new string[] { "PersonId" }));
                }

                if (!results.Any())
                {
                    if (_doctorService.PersonExists(PersonId))
                    {
                        results.Add(new ValidationResult("The person has already been added as a doctor.", new string[] { "PersonId" }));
                    }
                }
            }

            EncryptedPassword = _passwordEncryptionUtil.Encrypt(Password);

            return(results);
        }
예제 #2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            Validator.TryValidateProperty(this.Name, new ValidationContext(this, null, null)
            {
                MemberName = "Name"
            }, results);
            Validator.TryValidateProperty(this.Description, new ValidationContext(this, null, null)
            {
                MemberName = "Description"
            }, results);

            if (!results.Any())
            {
                if (_specializationService.Exists(this.Name))
                {
                    results.Add(new ValidationResult($"Specialization ({this.Name}) already exists.", new List <string> {
                        "Name"
                    }));
                }
            }
            return(results);
        }