public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Lat,Long")] PostoCombustivel postoCombustivel) { if (id != postoCombustivel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(postoCombustivel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostoCombustivelExists(postoCombustivel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(postoCombustivel)); }
public async Task <IActionResult> Create([Bind("Id,Nome,Lat,Long")] PostoCombustivel postoCombustivel) { if (ModelState.IsValid) { _context.Add(postoCombustivel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(postoCombustivel)); }
public void CriarPosto(string Nome, decimal gasComum, decimal gasAdit, decimal etanolComum, decimal etanolAdit, decimal latitude, decimal longitude) { var novoPosto = new Posto { Nome = Nome, DataInclusao = DateTime.Now, Latitude = latitude, Longitude = longitude }; var novoGasComum = new PostoCombustivel { Preco = gasComum, CombustivelId = 1 }; var novoGasAdit = new PostoCombustivel { Preco = gasAdit, CombustivelId = 2 }; var novoEtanolComum = new PostoCombustivel { Preco = etanolComum, CombustivelId = 3 }; var novoEtanolAdit = new PostoCombustivel { Preco = etanolAdit, CombustivelId = 4 }; novoPosto.PostoCombustivel.Add(novoGasComum); novoPosto.PostoCombustivel.Add(novoGasAdit); novoPosto.PostoCombustivel.Add(novoEtanolComum); novoPosto.PostoCombustivel.Add(novoEtanolAdit); _contexto.Posto.Add(novoPosto); _contexto.SaveChanges(); }