public void Delete(_Cep oAnexo) { using (Database db = new NPoco.Database("Teste")) { db.Delete <_Cep>(oAnexo); } }
public async Task <IActionResult> Put_Cep(string id, _Cep _Cep) { if (id != _Cep.Cep) { return(BadRequest()); } _context.Entry(_Cep).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_CepExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult PesquisarCep(string cep) { string url = $@"https://viacep.com.br/ws/{cep}/json/"; WebClient client = new WebClient(); var test = client.DownloadString(url); _Cep cepx = JsonConvert.DeserializeObject <_Cep>(test); var aux = from a in _context.Ceps where a.Cep == cepx.Cep select a; var cadastro = aux.FirstOrDefault(); if (cadastro == null) { _context.Add(cepx); _context.SaveChanges(); return(RedirectToAction("Index")); } else { ViewData["Message"] = "Cep já cadastrado"; return(RedirectToAction("Index")); } }
public _Cep Update(_Cep oAnexo) { using (Database db = new NPoco.Database("Teste")) { db.Update(oAnexo); return(oAnexo); } }
public _Cep Insert(_Cep oAnexo) { using (Database db = new NPoco.Database("Teste")) { db.Insert <_Cep>(oAnexo); return(oAnexo); } }
public void GravaCep(_Cep cep) { _CepData data = new _CepData(); try { data.Insert(cep); } catch (Exception) { } finally { } }
public async Task <ActionResult <_Cep> > Post_Cep(_Cep _Cep) { _context.Ceps.Add(_Cep); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (_CepExists(_Cep.Cep)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("Get_Cep", new { id = _Cep.Cep }, _Cep)); }