Exemplo n.º 1
0
        /// <summary>
        /// Converte um fornecedor de Model para Dto
        /// </summary>
        /// <param name="fornecedorDto"></param>
        /// <param name="mensagemErro"></param>
        /// <returns></returns>
        public bool ConverterModelParaDto(ref FornecedorDto fornecedorDto, ref string mensagemErro)
        {
            try
            {
                fornecedorDto.Cnpj = string.IsNullOrWhiteSpace(Cnpj) ? "" : Cnpj.Trim().Replace(".", "").Replace("-", "").Replace("-", "");
                fornecedorDto.ComplementoEndereco = string.IsNullOrWhiteSpace(ComplementoEndereco) ? "" : ComplementoEndereco.Trim();
                fornecedorDto.NomeFantasia        = string.IsNullOrWhiteSpace(NomeFantasia) ? "" : NomeFantasia.Trim();
                fornecedorDto.NumeroEndereco      = string.IsNullOrWhiteSpace(NumeroEndereco) ? "" : NumeroEndereco.Trim();
                fornecedorDto.Obs           = string.IsNullOrWhiteSpace(Obs) ? "" : Obs.Trim();
                fornecedorDto.RazaoSocial   = string.IsNullOrWhiteSpace(RazaoSocial) ? "" : RazaoSocial.Trim();
                fornecedorDto.Telefone      = string.IsNullOrWhiteSpace(Telefone) ? "" : Telefone.Trim();
                fornecedorDto.DataAlteracao = this.DataAlteracao;
                fornecedorDto.DataInclusao  = this.DataInclusao;
                fornecedorDto.Id            = this.Id;
                fornecedorDto.Inativo       = this.Inativo;

                fornecedorDto.Endereco.Bairro     = string.IsNullOrWhiteSpace(Endereco.Bairro) ? "" : Endereco.Bairro.Trim();
                fornecedorDto.Endereco.Cep        = string.IsNullOrWhiteSpace(Endereco.Cep) ? "" : Endereco.Cep.Trim().Replace("-", "");
                fornecedorDto.Endereco.Cidade     = string.IsNullOrWhiteSpace(Endereco.Cidade) ? "" : Endereco.Cidade.Trim();
                fornecedorDto.Endereco.Logradouro = string.IsNullOrWhiteSpace(Endereco.Logradouro) ? "" : Endereco.Logradouro.Trim();
                fornecedorDto.Endereco.Id         = Endereco.Id;

                return(true);
            }
            catch (Exception ex)
            {
                mensagemErro = ex.Message;
                return(false);
            }
        }
Exemplo n.º 2
0
        public override void Trim()
        {
            CompanyName = CompanyName.IsNullOrWhiteSpace() ? CompanyName : CompanyName.Trim();
            TradeName   = TradeName.IsNullOrWhiteSpace() ? TradeName : TradeName.Trim();
            Cnpj        = Cnpj.IsNullOrWhiteSpace() ? Cnpj : Cnpj.Trim();
            Ie          = Ie.IsNullOrWhiteSpace() ? Ie : Ie.Trim();
            Im          = Im.IsNullOrWhiteSpace() ? Im : Im.Trim();

            base.Trim();
        }
Exemplo n.º 3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            int[] multiplicador1 = new int[12] {
                5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int[] multiplicador2 = new int[13] {
                6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int    soma;
            int    resto;
            string digito;
            string tempCnpj;
            string cnpj1;

            cnpj1 = Cnpj.Trim();
            cnpj1 = cnpj1.Replace(".", "").Replace("-", "").Replace("/", "");
            if (cnpj1.Length != 14)
            {
                yield return(new ValidationResult("Cnpj inválido"));
            }
            tempCnpj = cnpj1.Substring(0, 12);
            soma     = 0;
            for (int i = 0; i < 12; i++)
            {
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador1[i];
            }
            resto = (soma % 11);
            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }
            digito   = resto.ToString();
            tempCnpj = tempCnpj + digito;
            soma     = 0;
            for (int i = 0; i < 13; i++)
            {
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador2[i];
            }
            resto = (soma % 11);
            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }
            digito = digito + resto.ToString();
        }
Exemplo n.º 4
0
        public override bool ValidadorDocumento()
        {
            int[] multiplicador1 = new int[12] {
                5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int[] multiplicador2 = new int[13] {
                6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int    soma;
            int    resto;
            string digito;
            string tempCnpj;

            Cnpj = Cnpj.Trim();
            Cnpj = Cnpj.Replace(".", "").Replace("-", "").Replace("/", "");

            if (Cnpj.Length != 14)
            {
                return(false);
            }

            tempCnpj = Cnpj.Substring(0, 12);

            soma = 0;
            for (int i = 0; i < 12; i++)
            {
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador1[i];
            }

            resto = (soma % 11);
            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }

            digito = resto.ToString();

            tempCnpj = tempCnpj + digito;
            soma     = 0;
            for (int i = 0; i < 13; i++)
            {
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador2[i];
            }

            resto = (soma % 11);
            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }

            digito = digito + resto.ToString();

            return(Cnpj.EndsWith(digito));
        }