public override bool IsSatisfiedBy(Board target)
        {
            if (target.Owner == null)
            {
                SpecificationResult.AddError(
                    (int)DomainErrors.BoardDoesNotHaveOwner,
                    DomainMessageHelper.MessageHandler.GetMessageFromEnum(DomainErrors.BoardDoesNotHaveOwner));
            }

            return(!SpecificationResult.HasError);
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether [is satisfied by] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public override bool IsSatisfiedBy(TaskList target)
        {
            if (target.Board == null)
            {
                SpecificationResult.AddError(
                    (int)DomainErrors.TaskListDoesNothaveBoard,
                    DomainMessageHelper.MessageHandler.GetMessageFromEnum(DomainErrors.TaskListDoesNothaveBoard));
            }

            return(!SpecificationResult.HasError);
        }
        /// <summary>
        /// Determines whether [is satisfied by] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public override bool IsSatisfiedBy(User target)
        {
            if (m_usersToCheck.Count(x => x.Username == target.Username) > 0)
            {
                SpecificationResult.AddError(
                   (int)DomainErrors.UserUsernameAlreadyExists,
                   DomainMessageHelper.MessageHandler.GetMessageFromEnum(DomainErrors.UserUsernameAlreadyExists));
            }

            return base.IsSatisfiedBy(target);
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether [is satisfied by] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public override bool IsSatisfiedBy(User target)
        {
            if (string.IsNullOrEmpty(target.Password) || target.Password.Length < 6)
            {
                SpecificationResult.AddError(
                    (int)DomainErrors.UserDoesNotHaveValidPassword,
                    DomainMessageHelper.MessageHandler.GetMessageFromEnum(DomainErrors.UserDoesNotHaveValidPassword),
                    "password");
            }

            return(base.IsSatisfiedBy(target));
        }
Beispiel #5
0
        /// <summary>
        /// Determines whether the target object satisfies the specification.
        /// </summary>
        /// <param name="target">The target object to be validated.</param>
        /// <returns><c>true</c> if this instance is satisfied by the specified target; otherwise, <c>false</c>.</returns>
        public override bool IsSatisfiedBy(TTarget target)
        {
            var targetType = target.GetType();

            var propertiesToValidate = targetType.GetProperties()
                                       .Where(x => x.GetCustomAttributes(typeof(ValidationAttribute), true).Any());

            foreach (var property in propertiesToValidate)
            {
                foreach (ValidationAttribute attributeToValidate in property.GetCustomAttributes(typeof(ValidationAttribute), true))
                {
                    var isValid = attributeToValidate.IsValid(property.GetValue(target));

                    if (!isValid)
                    {
                        SpecificationResult
                        .AddError(GetErrorFromInvalidAttribute(attributeToValidate, property.Name));
                    }
                }
            }

            return(base.IsSatisfiedBy(target));
        }