public IActionResult DeleteEndereco(int id) { if (id > 0) { ProprietarioEndereco proprietarioEndereco = _context.ProprietarioEnderecos .Where(p => p.Id.Equals(id)) .ToList() .FirstOrDefault(p => p.Id == id); return(View(proprietarioEndereco)); } return(View()); }
public IActionResult AddEndereco(int id) { //https://www.talkingdotnet.com/handle-ajax-requests-in-asp-net-core-razor-pages/ //http://binaryintellect.net/articles/16ecfe49-98df-4305-b53f-2438d836f0d0.aspx string retorno = null; { MemoryStream stream = new MemoryStream(); Request.Body.CopyTo(stream); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { string requestBody = reader.ReadToEnd(); if (requestBody.Length > 0) { var obj = JsonConvert.DeserializeObject <ProprietarioEndereco>(requestBody); ProprietarioEndereco ObjTabela = JsonConvert.DeserializeObject <ProprietarioEndereco>(requestBody); //Verifica se o Proprietário já esta adicionado à Doadora int count = _context.ProprietarioEnderecos .Where(a => a.EnderecoTipo == ObjTabela.EnderecoTipo && a.ProprietarioId == ObjTabela.ProprietarioId).Count(); if (count == 0) { _context.ProprietarioEnderecos.Add(ObjTabela); _context.SaveChanges(); retorno = "NOVO"; return(new JsonResult(retorno)); } else { retorno = "EXISTE"; return(new JsonResult(retorno)); } } } } return(new JsonResult(retorno)); }
public void Remover(ProprietarioEndereco proprietarioEndereco) { _context.ProprietarioEnderecos.Remove(proprietarioEndereco); _context.SaveChanges(); }
public void Editar(ProprietarioEndereco proprietarioEndereco) { _context.Entry(proprietarioEndereco).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); }
//[ValidateAntiForgeryToken] public IActionResult DeleteEndereco(ProprietarioEndereco proprietarioEndereco) { _proprietarioEnderecoRepository.Remover(proprietarioEndereco); return(RedirectToRoute(new { Controller = "Proprietario", Action = "Edit", id = proprietarioEndereco.ProprietarioId })); }