Exemple #1
0
        public ValidationResult Validate(Customer record)
        {
            var result = new MultipleAttributeValidationResult();

            if (record.Name != null && record.Name.Length == 0)
            {
                result.AddError("name", MultipleAttributeValidationResult.Error.BLANK_ATTRIBUTE);
            }

            if (record.Cpf != null)
            {
                if (!validCpf(record.Cpf))
                {
                    result.AddError("cpf", MultipleAttributeValidationResult.Error.INVALID_CPF);
                }
                else
                {
                    if (customerRepo.Any(c => c.Cpf.Equals(record.Cpf) && (record.Id == null || !record.Id.Equals(c.Id))))
                    {
                        result.AddError("cpf", MultipleAttributeValidationResult.Error.IN_USE_BY_ACTIVE);
                    }

                    if (customerRepo.DeadRecordsRepo().Any(c => c.Cpf.Equals(record.Cpf) && (record.Id == null || !record.Id.Equals(c.Id))))
                    {
                        result.AddError("cpf", MultipleAttributeValidationResult.Error.IN_USE_BY_INACTIVE);
                    }
                }
            }

            return(result);
        }
        public ValidationResult Validate(Sale record)
        {
            var result = new MultipleAttributeValidationResult();

            if (record.SaleDate.HasValue)
            {
                if (record.SaleDate.Value.Subtract(DateTime.Today).TotalDays > 10)
                {
                    result.AddError("saleDate", MultipleAttributeValidationResult.Error.AFTER_TEN_DAYS);
                }

                if (record.SaleDate.Value.Subtract(DateTime.Today).TotalDays < -10)
                {
                    result.AddError("saleDate", MultipleAttributeValidationResult.Error.BEFORE_TEN_DAYS);
                }
            }

            if (record.Quantity.HasValue)
            {
                if (record.Quantity < 1)
                {
                    result.AddError("quantity", MultipleAttributeValidationResult.Error.LESS_THAN_ONE);
                }

                if (record.Product != null && record.Quantity > record.Product.Amount)
                {
                    result.AddError("quantity", MultipleAttributeValidationResult.Error.NOT_ENOUGH_INVENTORY);
                }
            }

            return(result);
        }
        private void DisplayErrors()
        {
            var validatorResult = (MultipleAttributeValidationResult)persister.ValidatorErrors(validator);
            var castResult = (MultipleAttributeValidationResult)persister.CasterErrors();
            var result = new MultipleAttributeValidationResult[] { castResult, validatorResult };

            foreach (var presenter in presenters)
                presenter.displayMesssages(result);
        }
        private void displayErrors()
        {
            var castErrors = (MultipleAttributeValidationResult)persister.CasterErrors();
            var results = new MultipleAttributeValidationResult[] { castErrors };
            var passwordResult = (PasswordValidator.UserPasswordValidationResult)persister.ValidatorErrors(validator);

            foreach (var presenter in errorPresenters)
                presenter.displayMesssages(results);

            if (passwdPresenter != null)
                passwdPresenter.displayMesssages(passwordResult);

            PasswordWarningPresenter.present(passwordResult, lblPasswordWarn);
        }
Exemple #5
0
        public ValidationResult Validate(User record)
        {
            var result = new MultipleAttributeValidationResult();

            if (record.Name != null && record.Name.Length == 0)
            {
                result.AddError("name", MultipleAttributeValidationResult.Error.BLANK_ATTRIBUTE);
            }

            if (record.Email == null || record.Email.Length == 0)
            {
                result.AddError("email", MultipleAttributeValidationResult.Error.BLANK_ATTRIBUTE);
            }

            if (record.Email != null && !record.Email.Contains("@"))
            {
                result.AddError("email", MultipleAttributeValidationResult.Error.INVALID_EMAIL);
            }

            return(result);
        }
        public ValidationResult Validate(Product record)
        {
            var result = new MultipleAttributeValidationResult();

            if (record.Name != null && record.Name.Length == 0)
            {
                result.AddError("name", MultipleAttributeValidationResult.Error.BLANK_ATTRIBUTE);
            }

            if (record.Amount < 0)
            {
                result.AddError("amount", MultipleAttributeValidationResult.Error.AMOUNT_LESS_THAN_0);
            }

            if (record.Price <= 0)
            {
                result.AddError("price", MultipleAttributeValidationResult.Error.INVALID_PRICE);
            }

            return(result);
        }
        private void displayValidationErrors()
        {
            var castErrors = (MultipleAttributeValidationResult)persister.CasterErrors();
            var userErrors = (MultipleAttributeValidationResult)persister.ValidatorErrors(userValidator);
            var results = new MultipleAttributeValidationResult[] { castErrors, userErrors };

            foreach (var presenter in errorPresenters)
                presenter.displayMesssages(results);
        }