public IEnumerable <string[]> Validate() { var validationResults = new List <string[]>(); if (string.IsNullOrWhiteSpace(Nome)) { validationResults.Add(new string[] { "O nome é obrigatório.", "Nome" }); } else if (Nome.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "Nome" }); } if (string.IsNullOrWhiteSpace(DataNascimento)) { validationResults.Add(new string[] { "A data de nascimento é obrigatória.", "DataNascimento" }); } if (string.IsNullOrWhiteSpace(Rg)) { validationResults.Add(new string[] { "O RG é obrigatório.", "Rg" }); } if (string.IsNullOrWhiteSpace(OrgaoRG)) { validationResults.Add(new string[] { "O orgão expeditor é obrigatório.", "OrgaoRG" }); } if (string.IsNullOrWhiteSpace(Cpf)) { validationResults.Add(new string[] { "O CPF é obrigatório.", "Cpf" }); } if (string.IsNullOrWhiteSpace(NomeMae)) { validationResults.Add(new string[] { "O nome da mãe é obrigatório.", "NomeMae" }); } if (string.IsNullOrWhiteSpace(Nacionalidade)) { validationResults.Add(new string[] { "A nacionalidade é obrigatória.", "Nacionalidade" }); } if (string.IsNullOrWhiteSpace(Naturalidade)) { validationResults.Add(new string[] { "A naturalidade é obrigatória.", "Naturalidade" }); } if (!Sexo.HasValue) { validationResults.Add(new string[] { "Informe o sexo.", "Sexo" }); } if (!EstadoCivil.HasValue) { validationResults.Add(new string[] { "O estado civil é obrigatório.", "EstadoCivil" }); } if (string.IsNullOrWhiteSpace(Telefone)) { validationResults.Add(new string[] { "O telefone é obrigatório.", "Telefone" }); } else if (Telefone.Length < 10 || Telefone.Length > 15) { validationResults.Add(new string[] { "Telefone inválido.", "Telefone" }); } if (string.IsNullOrWhiteSpace(Celular)) { validationResults.Add(new string[] { "O celular é obrigatório.", "Celular" }); } else if (Celular.Length < 10 || Celular.Length > 15) { validationResults.Add(new string[] { "Celular inválido.", "Celular" }); } if (string.IsNullOrWhiteSpace(Email)) { validationResults.Add(new string[] { "E-mail é obrigatório.", "Email" }); } else if (!Util.IsValidEmail(Email)) { validationResults.Add(new string[] { "E-mail inválido.", "Email" }); } if (string.IsNullOrWhiteSpace(Participacao)) { validationResults.Add(new string[] { "A participação é obrigatório.", "Participacao" }); } if (string.IsNullOrWhiteSpace(Rua)) { validationResults.Add(new string[] { "O nome da rua é obrigatório.", "Rua" }); } else if (Rua.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "Rua" }); } if (!string.IsNullOrWhiteSpace(Numero)) { if (Numero.Length > 11) { validationResults.Add(new string[] { "Número máximo 11 caracteres.", "Numero" }); } } if (Complemento != null && Complemento.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "Complemento" }); } if (string.IsNullOrWhiteSpace(Bairro)) { validationResults.Add(new string[] { "O bairro é obrigatório.", "Bairro" }); } else if (Bairro.Length > 100) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 100.", "Bairro" }); } if (string.IsNullOrWhiteSpace(Cidade)) { validationResults.Add(new string[] { "Cidade é obrigatório.", "Cidade" }); } else if (Cidade.Length > 100) { validationResults.Add(new string[] { "Cidade máximo 100 caracteres.", "Cidade" }); } if (!string.IsNullOrWhiteSpace(Cep)) { if (Cep.Replace(".", "").Replace("-", "").Trim().Length != 8) { validationResults.Add(new string[] { "CEP inválido.", "Cep" }); } } if (!Estado.HasValue) { validationResults.Add(new string[] { "O estado é obrigatório.", "Estado" }); } return(validationResults); }
public void Adicionar(Cep cep) { _contexto.Ceps.Add(cep); _contexto.SaveChanges(); }
public void Editar(Cep cep) { _contexto.Entry(cep).State = EntityState.Modified; _contexto.SaveChanges(); }
/// <inheritdoc /> public string ObterEnderecoComoQuerty(Cep cep) => ObterEnderecoPorCepComoString(cep, ViaCepFormatoRequisicao.Querty);
public bool salvar(Cep cep) { bool retorno; try { string folder = @"C:\banco_cep"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } XmlTextWriter writer = new XmlTextWriter(@"C:\banco_cep\BaseCep.xml", System.Text.Encoding.UTF8); writer.WriteStartDocument(true); writer.Formatting = Formatting.Indented; writer.Indentation = 2; writer.WriteStartElement("CepRegistro"); writer.WriteStartElement("cep"); writer.WriteString(cep.cep); writer.WriteEndElement(); writer.WriteStartElement("bairro"); writer.WriteString(cep.bairro); writer.WriteEndElement(); writer.WriteStartElement("complemento"); writer.WriteString(cep.complemento); writer.WriteEndElement(); writer.WriteStartElement("gia"); writer.WriteString(cep.gia); writer.WriteEndElement(); writer.WriteStartElement("ibge"); writer.WriteString(cep.ibge); writer.WriteEndElement(); writer.WriteStartElement("logradouro"); writer.WriteString(cep.logradouro); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); retorno = true; } catch (Exception e) { retorno = false; } return(retorno); }
public CepTests() { _cepValido = new Cep("13185-352"); _cepInvalido = new Cep("13185352"); }
/// <inheritdoc /> public string ObterEnderecoComoJson(Cep cep) => ObterEnderecoPorCepComoString(cep, ViaCepFormatoRequisicao.Json);
public Endereco ObterEndereco(Cep cep) { var json = ObterEnderecoComoJson(cep); return(EnderecoConvert.DeJsonParaEndereco(json)); }
public async Task <Endereco> ObterEnderecoAsync(Cep cep) { var json = await ObterEnderecoComoJsonAsync(cep); return(EnderecoConvert.DeJsonParaEndereco(json)); }
/// <inheritdoc /> public Task <XDocument> ObterEnderecoComoXmlAsync(Cep cep) => cep.IsEmpty
private void button1_Click(object sender, EventArgs e) { int nA = 0, nB = 0; string Target = this.textBox7.Text; nA = Convert.ToInt32(this.textBox5.Text); nB = Convert.ToInt32(this.textBox6.Text); string VT = this.textBox1.Text; string NT = this.textBox2.Text; string P = this.textBox3.Text; Exception E = new Exception(); if (NT.IndexOf(Target) == -1) { Target = "S"; } string S = "S"; int PN = 6; char[] vt, nt; vt = new char[VT.Length]; nt = new char[NT.Length]; int Cnt = NT.Length; for (int i = 0; i < VT.Length; i++) { vt[i] = VT[i]; } for (int i = 0; i < NT.Length; i++) { nt[i] = NT[i]; } int t = 0, lMax = 0; List <Pravila> Rules = new List <Pravila>(); P = P.Replace("\n", ""); P = P.Replace("\r", ""); P = P.Replace(" ", ""); List <string> Answers = new List <string>(); while (P.Length > 0) { t = 0; Pravila temp = new Pravila(); int pos = P.IndexOf('='); temp.A = P.Substring(0, pos); P = P.Substring(pos + 1); int tpos = P.IndexOf(';'); temp.B = new List <string>(); while (P[0] != ';') { if (P.IndexOf('|') > tpos || P.IndexOf('|') == -1) { temp.B.Add(P.Substring(0, P.IndexOf(';'))); P = P.Substring(P.IndexOf(';') + 1); break; } else { temp.B.Add(P.Substring(0, P.IndexOf('|'))); t = P.IndexOf('|') + 1; P = P.Substring(P.IndexOf('|') + 1); } tpos -= t; } for (int i = 0; i < temp.B.Count(); ++i) { temp.B[i] = temp.B[i].Replace("`", ""); } Rules.Add(temp); } List <Cep> ceps = new List <Cep>(); Cep slovo = new Cep() { A = Target, B = 0 }; ceps.Add(slovo); int index = 0; while (ceps.Count() > 0) { for (int i = 0; i < Rules.Count(); i++) { for (int j = 0; j < Rules[i].B.Count(); j++) { if (Rules[i].B[j].Length >= lMax) { lMax = Rules[i].B[j].Length; } if (ceps[index].A.Contains(Rules[i].A)) { string subs = ceps[index].A; subs = Replaceonce(subs, Rules[i].A, Rules[i].B[j]); Cep temp = new Cep() { A = subs, B = 0, C = 0 }; if (Checking(temp.A, nt, Cnt)) { if (temp.A.Length <= (PN + lMax)) { ceps.Add(temp); } } else { if (temp.A.Length <= nB && temp.A.Length >= nA) { Answers.Add(temp.A); } } } } } ceps.Remove(ceps[0]); } for (int i = 0; i < Answers.Count(); ++i) { textBox4.Lines = Answers.ToArray(); } }
/// <inheritdoc /> public Task <string> ObterEnderecoComoQuertyAsync(Cep cep) => cep.IsEmpty
/// <inheritdoc /> public Task <string> ObterEnderecoComoPipedAsync(Cep cep) => cep.IsEmpty
/// <inheritdoc /> public Task <Endereco> ObterEnderecoAsync(Cep cep) => cep.IsEmpty
private static IViaCepRequisicaoPor <Cep> NovaRequisicao(Cep cep, ViaCepFormatoRequisicao formato) => new ViaCepRequisicaoPorCep(cep, formato);
public void Cep_InValido() { var cep = "dfjdklj"; var obj = new Cep(cep); }
public IViaCepRequisicaoPor <Cep> NovaRequisicaoJson(Cep cep) => NovaRequisicao(cep, ViaCepFormatoRequisicao.Json);
public override int GetHashCode() => StreetAddress.GetHashCode() ^ Cep.GetHashCode() ^ City.GetHashCode() ^ UF.GetHashCode();
/// <inheritdoc /> public Endereco ObterEndereco(Cep cep) => _enderecoConvert.DeJsonParaEndereco(ObterEnderecoComoJson(cep));
public IEnumerable <string[]> Validate() { var validationResults = new List <string[]>(); if (string.IsNullOrWhiteSpace(NomeFantasia)) { validationResults.Add(new string[] { "O nome fantasia é obrigatório.", "NomeFantasia" }); } else if (NomeFantasia.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "NomeFantasia" }); } if (string.IsNullOrWhiteSpace(RazaoSocial)) { validationResults.Add(new string[] { "A razão social é obrigatória.", "RazaoSocial" }); } else if (RazaoSocial.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "RazaoSocial" }); } if (string.IsNullOrWhiteSpace(Cnpj)) { validationResults.Add(new string[] { "O CNPJ é obrigatório.", "Cnpj" }); } if (string.IsNullOrWhiteSpace(InscricaoEstadual)) { validationResults.Add(new string[] { "A inscrição estadual é obrigatória.", "InscricaoEstadual" }); } if (string.IsNullOrWhiteSpace(Email)) { validationResults.Add(new string[] { "E-mail é obrigatório.", "Email" }); } else if (!Util.IsValidEmail(Email)) { validationResults.Add(new string[] { "E-mail inválido.", "Email" }); } if (string.IsNullOrWhiteSpace(Telefone)) { validationResults.Add(new string[] { "O telefone é obrigatório.", "Telefone" }); } else if (Telefone.Length < 10 || Telefone.Length > 15) { validationResults.Add(new string[] { "Telefone inválido.", "Telefone" }); } if (string.IsNullOrWhiteSpace(Celular)) { validationResults.Add(new string[] { "O celular é obrigatório.", "Celular" }); } else if (Celular.Length < 10 || Celular.Length > 15) { validationResults.Add(new string[] { "Celular inválido.", "Celular" }); } if (string.IsNullOrWhiteSpace(NomeResponsavel)) { validationResults.Add(new string[] { "O nome do responsável é obrigatório.", "NomeResponsavel" }); } else if (NomeResponsavel.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "NomeResponsavel" }); } if (string.IsNullOrWhiteSpace(Rua)) { validationResults.Add(new string[] { "O nome da rua é obrigatório.", "Rua" }); } else if (Rua.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 255.", "Rua" }); } if (!string.IsNullOrWhiteSpace(Numero)) { if (Numero.Length > 11) { validationResults.Add(new string[] { "Número máximo 11 caracteres.", "Numero" }); } } if (Complemento != null && Complemento.Length > 255) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 150.", "Complemento" }); } if (string.IsNullOrWhiteSpace(Bairro)) { validationResults.Add(new string[] { "O bairro é obrigatório.", "Bairro" }); } else if (Bairro.Length > 150) { validationResults.Add(new string[] { "O máximo de caracteres neste campo é 150.", "Bairro" }); } if (string.IsNullOrWhiteSpace(Cidade)) { validationResults.Add(new string[] { "Cidade é obrigatório.", "Cidade" }); } else if (Cidade.Length > 100) { validationResults.Add(new string[] { "Cidade máximo 100 caracteres.", "Cidade" }); } if (!Estado.HasValue) { validationResults.Add(new string[] { "O estado é obrigatório.", "Estado" }); } if (!string.IsNullOrWhiteSpace(Cep)) { if (Cep.Replace(".", "").Replace("-", "").Trim().Length != 8) { validationResults.Add(new string[] { "CEP inválido.", "Cep" }); } } if (!TipoEmpresa.HasValue) { validationResults.Add(new string[] { "Informe o tipo da empresa.", "TipoEmpresa" }); } else if (TipoEmpresa == eTipoEmpresa.Filial && !MatrizId.HasValue) { validationResults.Add(new string[] { "Informe a matriz para essa empresa.", "MatrizId" }); } return(validationResults); }
/// <inheritdoc /> public string ObterEnderecoComoPiped(Cep cep) => ObterEnderecoPorCepComoString(cep, ViaCepFormatoRequisicao.Piped);
public void Cep_InValido() { var cep = "asfsaf"; var obj = new Cep(cep); }
/// <summary> /// Create ViaCep request uri from cep /// </summary> public Uri CreateRequestUri(Cep cep) { return(new Uri($"{_options.BaseAddress}/ws/{cep.Value}/json/unicode")); }
public IViaCepRequisicaoPor <Cep> NovaRequisicaoXml(Cep cep) => NovaRequisicao(cep, ViaCepFormatoRequisicao.Xml);
public async Task <IActionResult> PerfilUsuario(UserInformationViewModel user, IFormFile FotoLocal, int?CEPBD) { if (ModelState.IsValid) { _logger.LogInformation("Verificando se o perfil do usuário ja existe"); if (user.SobreUsuarioId == 0) { _logger.LogInformation("Cricando perfil do usuário"); SobreUsuario sobre = new SobreUsuario(); sobre.Formacao = user.Formacao; sobre.UsuarioId = user.Id; _logger.LogInformation("Buscando usuário para possiveis alteracoes"); var usuario = _contexto.Usuarios.FirstOrDefault(u => u.Id == user.Id); if (FotoLocal != null) { _logger.LogInformation("Enviando foto"); _logger.LogInformation("Criando link da pasta"); var fileName = ContentDispositionHeaderValue.Parse(FotoLocal.ContentDisposition).FileName.Trim('"'); //Assigning Unique Filename (Guid) var myUniqueFileName = Convert.ToString(Guid.NewGuid()); //Getting file Extension var FileExtension = Path.GetExtension(fileName); // concating FileName + FileExtension var newFileName = myUniqueFileName + FileExtension; // Combines two strings into a path. fileName = Path.Combine(_hostingEnvironment.WebRootPath, "Imagens") + $@"\{newFileName}"; // if you want to store path of folder in database using (FileStream fs = System.IO.File.Create(fileName)) { FotoLocal.CopyTo(fs); fs.Flush(); sobre.Foto = "~/Imagens/" + newFileName; } } _logger.LogInformation("validando cep"); if (CEPBD != null) { switch (CEPBD) { case null: _logger.LogInformation("Adicionando novo endereço ao banco"); Cep ceps = new Cep(); ceps.Logradouro = user.Logradouro; ceps.CEP = user.CEP; ceps.Bairro = user.Bairro; ceps.Cidade = user.Cidade; ceps.UF = user.UF; _contexto.Add(ceps); await _contexto.SaveChangesAsync(); _logger.LogInformation("associando ao usuário"); sobre.CepId = ceps.CepId; break; default: sobre.CepId = CEPBD; break; } } _logger.LogInformation("Validando se o usuário vai alterar a senha"); if (user.PasswordHash != null) { _logger.LogInformation("Criptografando senha do usuário"); var senhaCriptografada = Criptografia.Codifica(user.PasswordHash); usuario.PasswordHash = senhaCriptografada; _contexto.Update(usuario); await _contexto.SaveChangesAsync(); _logger.LogInformation("Atualizando senha do usuário"); } //Atualizando informações complementares do usuário var infoComplementares = _contexto.Usuarios.Where(u => u.Id == user.Id).FirstOrDefault(); infoComplementares.Telefone = user.Telefone; infoComplementares.Email = user.Email; infoComplementares.NormalizedEmail = user.Email.ToUpper(); infoComplementares.Numero = user.Numero; _contexto.Update(infoComplementares); await _contexto.SaveChangesAsync(); //fim da atualização complementar; _logger.LogInformation("Adicionando Informações complementares do usuario"); _contexto.SobreUsuarios.Add(sobre); await _contexto.SaveChangesAsync(); TempData["Mensagem"] = "Atualizado com sucesso"; return(RedirectToAction("PerfilUsuario", new { UsuarioId = user.Id })); } else { _logger.LogInformation("Usuário já possui perfil, atualizando então"); var sobreUsuario = _contexto.SobreUsuarios.FirstOrDefault(s => s.SobreUsuarioId == user.SobreUsuarioId); _logger.LogInformation("procurando perfil do usuário para atualização"); sobreUsuario.Formacao = user.Formacao; _logger.LogInformation("Validando CEP"); switch (CEPBD) { case null: _logger.LogInformation("Adicionando novo endereço ao banco"); Cep ceps = new Cep(); ceps.Logradouro = user.Logradouro; ceps.CEP = user.CEP; ceps.Bairro = user.Bairro; ceps.Cidade = user.Cidade; ceps.UF = user.UF; _contexto.Add(ceps); await _contexto.SaveChangesAsync(); _logger.LogInformation("associando ao convênio"); sobreUsuario.CepId = ceps.CepId; break; default: sobreUsuario.CepId = CEPBD; break; } if (FotoLocal != null) { if (sobreUsuario.Foto != null) { _logger.LogInformation("Excluindo foto antiga do servidor e adicionando nova"); string FotoUsuario = sobreUsuario.Foto; FotoUsuario = FotoUsuario.Replace("~", "wwwroot"); System.IO.File.Delete(FotoUsuario); } _logger.LogInformation("Criando link da pasta"); var fileName = ContentDispositionHeaderValue.Parse(FotoLocal.ContentDisposition).FileName.Trim('"'); //Assigning Unique Filename (Guid) var myUniqueFileName = Convert.ToString(Guid.NewGuid()); //Getting file Extension var FileExtension = Path.GetExtension(fileName); // concating FileName + FileExtension var newFileName = myUniqueFileName + FileExtension; // Combines two strings into a path. fileName = Path.Combine(_hostingEnvironment.WebRootPath, "Imagens/Usuarios") + $@"\{newFileName}"; // if you want to store path of folder in database using (FileStream fs = System.IO.File.Create(fileName)) { FotoLocal.CopyTo(fs); fs.Flush(); sobreUsuario.Foto = "~/Imagens/Usuarios/" + newFileName; } } if (user.PasswordHash != null) { _logger.LogInformation("Alterando senha do usuário"); var usuarioSenha = _contexto.Usuarios.FirstOrDefault(u => u.Id == user.Id); var senhaCriptografada = Criptografia.Codifica(user.PasswordHash); usuarioSenha.PasswordHash = senhaCriptografada; _contexto.Update(usuarioSenha); await _contexto.SaveChangesAsync(); } //Atualizando informações complementares do usuário var infoComplementares = _contexto.Usuarios.Where(u => u.Id == user.Id).FirstOrDefault(); infoComplementares.Telefone = user.Telefone; infoComplementares.Email = user.Email; infoComplementares.NormalizedEmail = user.Email.ToUpper(); infoComplementares.Numero = user.Numero; _contexto.Update(infoComplementares); await _contexto.SaveChangesAsync(); //fim da atualização complementar; _logger.LogInformation("Atualizando perfil do usuário"); _contexto.SobreUsuarios.Update(sobreUsuario); await _contexto.SaveChangesAsync(); TempData["Mensagem"] = "Atualizado com sucesso"; return(RedirectToAction("PerfilUsuario", new { UsuarioId = user.Id })); } } _logger.LogError("informações digitadas inválidas"); return(View(user)); }
public IViaCepRequisicaoPor <Cep> NovaRequisicaoPiped(Cep cep) => NovaRequisicao(cep, ViaCepFormatoRequisicao.Piped);
public void Apagar(Cep cep) { _contexto.Ceps.Remove(cep); _contexto.SaveChanges(); }
public IViaCepRequisicaoPor <Cep> NovaRequisicaoQuerty(Cep cep) => NovaRequisicao(cep, ViaCepFormatoRequisicao.Querty);
internal ViaCepFluentPorCep(Cep cep) { _cep = cep; _viaCep = new ViaCep(); }
public void ScrapException() { Cep.Scrap(string.Empty); }