Exemplo n.º 1
0
        /// <summary>
        /// Validates this instance to ensure it can be saved in a data repository.
        /// If this finds an issue, it throws a ValidationException for that.        
        /// This calls ValidateProperties(). Override this method to provide custom validation logic in a type.
        /// </summary>
        public override async Task Validate()
        {
            await base.Validate();

            if (IsNew && await Database.Any<Settings>())
                throw new Exception("Settings is Singleton!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates the data for the properties of this Content block.<para/>
        /// It throws a ValidationException if an error is detected.<para/>
        /// </summary>
        protected override void ValidateProperties()
        {
            var result = new List <string>();

            // Validate Content property:

            if (this.Content.IsEmpty())
            {
                result.Add("Content cannot be empty.");
            }

            // Validate Key property:

            if (this.Key.IsEmpty())
            {
                result.Add("Key cannot be empty.");
            }

            if (this.Key != null && this.Key.Length > 200)
            {
                result.Add("The provided Key is too long. A maximum of 200 characters is acceptable.");
            }

            // Ensure uniqueness of Key.

            if (Database.Any <ContentBlock>(c => c.Key == Key && c != this))
            {
                result.Add("Key must be unique. There is an existing Content block record with the provided Key.");
            }

            if (result.Any())
            {
                throw new ValidationException(result.ToLinesString());
            }
        }
Exemplo n.º 3
0
        protected override void ValidateProperties(ValidationResult result)
        {
            // Validate Email property:

            if (this.Email.LacksValue())
            {
                result.Add(nameof(Email), "Email cannot be empty.");
            }

            if (this.Email != null && this.Email.Length > 100)
            {
                result.Add(nameof(Email), "The provided Email is too long. A maximum of 100 characters is acceptable.");
            }

            // Ensure Email matches Email address pattern:

            if (this.Email.HasValue() && !System.Text.RegularExpressions.Regex.IsMatch(this.Email, "\\s*\\w+([-+.'\\w])*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\\s*"))
            {
                result.Add(nameof(Email), "The provided Email is not a valid Email address.");
            }

            // Ensure uniqueness of Email.

            if (Database.Any <User>(u => u.Email == this.Email && u != this))
            {
                result.Add(nameof(Email), "Email must be unique. There is an existing User record with the provided Email.");
            }

            // Validate FirstName property:

            if (this.FirstName.LacksValue())
            {
                result.Add(nameof(FirstName), "First name cannot be empty.");
            }

            if (this.FirstName != null && this.FirstName.Length > 200)
            {
                result.Add(nameof(FirstName), "The provided First name is too long. A maximum of 200 characters is acceptable.");
            }

            // Validate LastName property:

            if (this.LastName.LacksValue())
            {
                result.Add(nameof(LastName), "Last name cannot be empty.");
            }

            if (this.LastName != null && this.LastName.Length > 200)
            {
                result.Add(nameof(LastName), "The provided Last name is too long. A maximum of 200 characters is acceptable.");
            }

            // Validate Password property:

            if (this.Password != null && this.Password.Length > 100)
            {
                result.Add(nameof(Password), "The provided Password is too long. A maximum of 100 characters is acceptable.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates this instance to ensure it can be saved in a data repository.
        /// If this finds an issue, it throws a ValidationException for that.
        /// This calls ValidateProperties(). Override this method to provide custom validation logic in a type.
        /// </summary>
        public override void Validate(ValidationResult result)
        {
            base.Validate(result);

            if (IsNew && Database.Any <Settings>())
            {
                throw new Exception("Settings is Singleton!");
            }
        }
Exemplo n.º 5
0
        protected override void ValidateProperties(ValidationResult result)
        {
            // Validate Name property:

            if (this.Name.LacksValue())
            {
                result.Add(nameof(Name), "Name cannot be empty.");
            }

            if (this.Name != null && this.Name.Length > 100)
            {
                result.Add(nameof(Name), "The provided Name is too long. A maximum of 100 characters is acceptable.");
            }

            // Ensure uniqueness of Name.

            if (Database.Any <ContactType>(c => c.Name == this.Name && c != this))
            {
                result.Add(nameof(Name), "Name must be unique. There is an existing Contact type record with the provided Name.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Validates the data for the properties of this Background task and throws a ValidationException if an error is detected.<para/>
        /// </summary>
        protected override async Task ValidateProperties()
        {
            var result = new List <string>();

            if (IntervalInMinutes < 0)
            {
                result.Add("The value of Interval in minutes must be 0 or more.");
            }

            if (Name.IsEmpty())
            {
                result.Add("Name cannot be empty.");
            }

            if (Name?.Length > 200)
            {
                result.Add("The provided Name is too long. A maximum of 200 characters is acceptable.");
            }

            // Ensure uniqueness of Name.

            if (await Database.Any <BackgroundTask>(b => b.Name == Name && b != this))
            {
                result.Add("Name must be unique. There is an existing Background task record with the provided Name.");
            }

            if (TimeoutInMinutes < 0)
            {
                result.Add("The value of Timeout in minutes must be 0 or more.");
            }

            if (result.Any())
            {
                throw new ValidationException(result.ToLinesString());
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Validates the data for the properties of this User.<para/>
        /// It throws a ValidationException if an error is detected.<para/>
        /// </summary>
        protected override void ValidateProperties()
        {
            var result = new List <string>();

            // Validate Email property:

            if (this.Email.IsEmpty())
            {
                result.Add("Email cannot be empty.");
            }

            if (this.Email != null && this.Email.Length > 100)
            {
                result.Add("The provided Email is too long. A maximum of 100 characters is acceptable.");
            }

            // Ensure Email matches Email address pattern:

            if (this.Email.HasValue() && !System.Text.RegularExpressions.Regex.IsMatch(this.Email, "\\s*\\w+([-+.'\\w])*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\\s*"))
            {
                result.Add("The provided Email is not a valid Email address.");
            }

            // Ensure uniqueness of Email.

            if (Database.Any <User>(u => u.Email == Email && u != this))
            {
                result.Add("Email must be unique. There is an existing User record with the provided Email.");
            }

            // Validate FirstName property:

            if (this.FirstName.IsEmpty())
            {
                result.Add("First name cannot be empty.");
            }

            if (this.FirstName != null && this.FirstName.Length > 200)
            {
                result.Add("The provided First name is too long. A maximum of 200 characters is acceptable.");
            }

            // Validate LastName property:

            if (this.LastName.IsEmpty())
            {
                result.Add("Last name cannot be empty.");
            }

            if (this.LastName != null && this.LastName.Length > 200)
            {
                result.Add("The provided Last name is too long. A maximum of 200 characters is acceptable.");
            }

            // Validate Password property:

            if (this.Password != null && this.Password.Length > 100)
            {
                result.Add("The provided Password is too long. A maximum of 100 characters is acceptable.");
            }

            // Validate Salt property:

            if (this.Salt != null && this.Salt.Length > 200)
            {
                result.Add("The provided Salt is too long. A maximum of 200 characters is acceptable.");
            }

            if (result.Any())
            {
                throw new ValidationException(result.ToLinesString());
            }
        }