public IHttpActionResult PutProprietarios(int id, Proprietarios proprietarios) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != proprietarios.Id) { return(BadRequest()); } db.Entry(proprietarios).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProprietariosExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutImovel(int id, Imovel imovel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != imovel.Id) { return(BadRequest()); } db.Entry(imovel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ImovelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Cadastrar(Imovel imovel) { _context.Imoveis.Add(imovel); _context.SaveChanges(); TempData["msg"] = "Cadastrado!"; return(RedirectToAction("Cadastrar")); }
public ActionResult Cadastrar(Categoria categoria) { _context.Categorias.Add(categoria); _context.SaveChanges(); TempData["msg"] = "Categoria cadastrada!!!!!!!!"; return(View()); }
public ActionResult Cadastrar(Categoria categoria) { _context.Categorias.Add(categoria); _context.SaveChanges(); TempData["msg"] = "Categoria Cadastrada!"; return(RedirectToAction("Cadastrar")); }
protected override void Seed(ImobiliariaContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var listProprietarios = new List <Proprietario>() { new Proprietario() { Nome = "Francisco", Email = "*****@*****.**", DataNascimento = "28/02/1991" }, new Proprietario() { Nome = "Teste2", Email = "*****@*****.**", DataNascimento = "20/02/1991" } }; listProprietarios.ForEach(s => context.GetProprietarios.AddOrUpdate(x => x.Nome, s) ); context.SaveChanges(); var listaImoveis = new List <Imovel>() { new Imovel() { Cep = "88048301", Bairro = "Centro", Municipio = "Blumenau", Complemento = "casa", Numero = 20, Logradouro = "Rua teste", ProprietarioId = context.GetProprietarios.FirstOrDefault(x => x.Nome == "Francisco").Id }, new Imovel() { Cep = "88048300", Bairro = "Centro", Municipio = "Blumenau", Complemento = "casa", Numero = 20, Logradouro = "Rua teste2", ProprietarioId = context.GetProprietarios.FirstOrDefault(x => x.Nome == "Teste2").Id } }; listaImoveis.ForEach(s => context.GetImovels.AddOrUpdate(x => new { x.ProprietarioId, x.Cep }, s) ); context.SaveChanges(); //context.GetProprietarios.AddOrUpdate(x => x.Nome, new Models.Proprietario() //{ // Nome = "Francisco", // Email = "*****@*****.**", // DataNascimento = "28/02/1991" //}); //context.GetImovels.AddOrUpdate(x => x.Cep, new Models.Imovel() //{ // Cep = "88048301", // Bairro = "Centro", // Municipio = "Blumenau", // Complemento = "casa", // Numero = 20, // Logradouro = "Rua teste" //}); //context.SaveChanges(); }