public IActionResult Post([FromBody] CasaShowTemp cTemp) { try { CasaShow c = new CasaShow(); c.Nome = cTemp.Nome; if (c.Nome == null || c.Nome.Length < 1) { Response.StatusCode = 400; return(new ObjectResult("Nome Inválido")); } c.Endereco = cTemp.Endereco; if (c.Endereco == null || c.Endereco.Length < 1) { Response.StatusCode = 400; return(new ObjectResult("Endereço Inválido")); } database.CasaShows.Add(c); database.SaveChanges(); Response.StatusCode = 201; return(new ObjectResult("Casa criada com sucesso")); } catch { Response.StatusCode = 500; return(new ObjectResult("Erro (requisição vazia)")); } }
public IActionResult Deletar(int id) { CasaShow casa = Data.CasaShows.First(registroCasa => registroCasa.Id == id); Data.CasaShows.Remove(casa); Data.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Get(int id) { try { CasaShow casaShow = database.CasaShows.First(c => c.Id == id); return(Ok(casaShow)); } catch (Exception) { Response.StatusCode = 404; return(new ObjectResult("Id inválido")); } }
public IActionResult Salvar(CasaShow casa) { if (casa.Id == 0) { Data.CasaShows.Add(casa); } else { CasaShow casaDoBanco = Data.CasaShows.First(registroCasa => registroCasa.Id == casa.Id); casaDoBanco.Nome = casa.Nome; casaDoBanco.Endereco = casa.Endereco; } Data.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Delete(int id) { try { CasaShow casaShow = database.CasaShows.First(c => c.Id == id); database.CasaShows.Remove(casaShow); database.SaveChanges(); return(new ObjectResult("Casa deletada com sucesso")); } catch (Exception) { Response.StatusCode = 404; return(new ObjectResult("Id inválido")); } }
public IActionResult Salvar(CasaShowDTO casaTemporaria) { if (ModelState.IsValid) { CasaShow casashow = new CasaShow(); casashow.Nome = casaTemporaria.Nome; casashow.Local = casaTemporaria.Local; casashow.Status = true; database.CasasShows.Add(casashow); database.SaveChanges(); return(RedirectToAction("CasaShows", "Admin")); } else { return(View("../Admin/NovoCasaShow")); } }
public IActionResult Post([FromBody] CasaShowDTO clubTemporary) { if (clubTemporary.Nome.Length <= 1) { Response.StatusCode = 400; return(new ObjectResult(new { msg = "O Nome deve ter mais de 1 caracter." })); } if (clubTemporary.Local.Length <= 1) { Response.StatusCode = 400; return(new ObjectResult(new { msg = "O Local deve ter mais de 1 caracter." })); } CasaShow club = new CasaShow(); club.Nome = clubTemporary.Nome; club.Local = clubTemporary.Local; club.Status = true; database.CasasShows.Add(club); database.SaveChanges(); Response.StatusCode = 201; return(new ObjectResult("")); }
public IActionResult Editar(int id) { CasaShow casa = Data.CasaShows.First(registroCasa => registroCasa.Id == id); return(View("Cadastrar", casa)); }