Exemple #1
0
        /// <summary>
        /// Valida as propriedades da entidade
        /// </summary>
        public void ValidarEntidade()
        {
            var regrasException = new RegrasException <Usuario>();

            // se algum erro foi adicionado à lista de erros, dispara exceção
            if (regrasException.Erros.Any())
            {
                throw regrasException;
            }
        }
Exemple #2
0
        private void ValidarCNPJ(string cnpj)
        {
            if (_validatorService == null)
            {
                return;
            }

            var regrasException = new RegrasException <Empresa>();

            if (!_validatorService.IsCNPJValid(cnpj))
            {
                regrasException.AdicionarErroPara(x => x.CNPJ, "CNPJ inválido");
            }

            if (regrasException.Erros.Any())
            {
                throw regrasException;
            }
            else
            {
                if (_empresaService == null)
                {
                    return;
                }

                if (IdEmpresa > 0)
                {
                    if (_empresaService.Any(emp => emp.CNPJ.Equals(cnpj) && emp.IdEmpresa != IdEmpresa))
                    {
                        regrasException.AdicionarErroPara(x => x.CNPJ, "Já existe uma empresa com este CNPJ");
                    }
                }
                else
                {
                    if (_empresaService.Any(emp => emp.CNPJ.Equals(cnpj)))
                    {
                        regrasException.AdicionarErroPara(x => x.CNPJ, "Já existe uma empresa com este CNPJ");
                    }
                }

                if (regrasException.Erros.Any())
                {
                    throw regrasException;
                }
            }
        }