예제 #1
0
        /// <summary>
        ///     <para>Valida os campos do Model</para>
        ///     <para>Documentação: <see cref="https://valitdocs.readthedocs.io/en/latest/validation-rules/index.html" /> </para>
        /// </summary>
        /// <param name="data">Objeto com valor dos atributos do Model Item</param>
        /// <returns>Retorna booleano e Mensagem</returns>
        public bool ValidarDados(PessoaEndereco data)
        {
            var result = ValitRules <PessoaEndereco>
                         .Create()
                         .Ensure(m => m.Cep, _ => _
                                 .Required()
                                 .WithMessage("CEP é obrigatorio.")
                                 .MinLength(8)
                                 .WithMessage("O CEP não tem um formato válido.")
                                 .MaxLength(9)
                                 .WithMessage("O CEP não tem um formato válido."))
                         .For(data)
                         .Validate();

            if (!result.Succeeded)
            {
                foreach (var message in result.ErrorMessages)
                {
                    Alert.Message("Opss!", message, Alert.AlertType.error);
                    return(true);
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
        public bool Save(PessoaEndereco data, bool message = true)
        {
            if (ValidarDados(data))
            {
                return(false);
            }

            data.id_empresa = Program.UNIQUE_ID_EMPRESA;

            if (data.Id == 0)
            {
                data.id_sync     = Validation.RandomSecurity();
                data.status_sync = "CREATE";
                data.Criado      = DateTime.Now;
                if (Data(data).Create() == 1)
                {
                    if (message)
                    {
                        Alert.Message("Tudo certo!", "Endereço salvo com sucesso.", Alert.AlertType.success);
                    }

                    return(true);
                }

                if (message)
                {
                    Alert.Message("Opss", "Erro ao criar, verifique os dados.", Alert.AlertType.error);
                }
            }

            if (data.Id > 0)
            {
                if (!data.IgnoringDefaults)
                {
                    data.status_sync = "UPDATE";
                    data.Atualizado  = DateTime.Now;
                }

                if (Data(data).Update("ID", data.Id) == 1)
                {
                    if (message)
                    {
                        Alert.Message("Tudo certo!", "Endereço atualizado com sucesso.", Alert.AlertType.success);
                    }

                    return(true);
                }

                if (message)
                {
                    Alert.Message("Opss", "Erro ao atualizar, verifique os dados.", Alert.AlertType.error);
                }
            }

            return(false);
        }
예제 #3
0
        public Pessoa FromCsv(string csvLine, string tipo = "Clientes")
        {
            var values = csvLine.Split(';');

            Id         = 0;
            Tipo       = tipo;
            Excluir    = 0;
            Atualizado = DateTime.Now;
            Nome       = values[0];

            var rnd = new Random();

            if (ExistsName(Nome))
            {
                Nome = Nome + " " + rnd.Next(1, 10);

                if (ExistsName(Nome))
                {
                    Nome = Nome + " " + rnd.Next(1, 10);
                }
            }

            Fantasia         = values[1];
            RG               = values[2];
            CPF              = values[3];
            Aniversario      = values[4] == "0000-00-00" ? null : values[4];
            Isento           = Validation.ConvertToInt32(values[5]);
            Transporte_placa = values[6];
            Transporte_uf    = values[7];
            Transporte_rntc  = values[8];

            if (Save(this, false))
            {
                if (!string.IsNullOrEmpty(values[9]))
                {
                    var contato = new PessoaContato
                    {
                        Id_pessoa = GetLastId(),
                        Excluir   = 0,
                        Contato   = values[9],
                        Telefone  = values[10],
                        Celular   = values[11],
                        Email     = values[12]
                    };
                    contato.Save(contato, false);
                }

                if (!string.IsNullOrEmpty(values[13]))
                {
                    var addr = new PessoaEndereco
                    {
                        Id_pessoa   = GetLastId(),
                        Excluir     = 0,
                        Cep         = values[13],
                        Estado      = values[14],
                        Cidade      = values[15],
                        Rua         = values[16],
                        Nr          = values[17],
                        Complemento = values[18],
                        Bairro      = values[19],
                        Pais        = values[20],
                        IBGE        = values[21]
                    };
                    addr.Save(addr, false);
                }
            }

            return(this);
        }