//METODO DE BUSCA POR ID public EstadoModel SelectByID(int id) { try { String sql = "SELECT est_cod, est_nome FROM estado WHERE est_cod = @id"; con = Conexao.conectar(); MySqlCommand cmd = new MySqlCommand(sql, con); cmd.Parameters.AddWithValue("@id", id); MySqlDataReader dr; EstadoModel estado = new EstadoModel(); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { estado.est_cod = Convert.ToInt32(dr["est_cod"]); estado.est_nome = dr["est_nome"].ToString(); } return(estado); } catch (Exception ex) { throw ex; } finally { Conexao.fechar(); } }
public JsonResult ExcluirEstado(int id) { var ok = EstadoModel.ExcluirPeloId(id); var quant = EstadoModel.RecuperarQuantidade(); return(Json(new { Ok = ok, Quantidade = quant })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,PaisId")] EstadoModel estadoModel) { if (id != estadoModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { estadoModel.Nome = estadoModel.Nome.ToUpper(); _context.Update(estadoModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EstadoModelExists(estadoModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PaisId"] = new SelectList(_context.PaisModel, "Id", "Nome", estadoModel.PaisId); return(View(estadoModel)); }
public JsonResult SalvarEstado(EstadoModel model) { var resultado = "OK"; var mensagens = new List <string>(); var idSalvo = string.Empty; if (!ModelState.IsValid) { resultado = "AVISO"; mensagens = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList(); } else { try { var id = model.Salvar(); if (id > 0) { idSalvo = id.ToString(); } else { resultado = "ERRO"; } } catch (Exception ex) { resultado = "ERRO"; } } return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo })); }
public List <EstadoModel> ListarEstado(int idPais) { try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT * FROM Estado WHERE id_pais = @idPais"; cmd.Parameters.AddWithValue("@idPais", idPais); SqlDataReader dr = cmd.ExecuteReader(); List <EstadoModel> lista = new List <EstadoModel>(); while (dr.Read()) { int idEstado = Convert.ToInt32(dr["id_estado"]); string nomeEstado = dr["nome_estado"].ToString(); EstadoModel estado = new EstadoModel(idEstado, nomeEstado, idPais); lista.Add(estado); } con.Desconectar(); return(lista); } catch (Exception e) { throw e; } }
private void CarregaDados(EstadoModel _Registro) { if (_Registro != null && _Registro.NOME != null && _Registro.NOME.Trim() != "") { grpSelecionado.IsVisible = true; lblRegistroSelecionado.Text = _Registro.NOME; } }
public ActionResult DeleteConfirmed(int id) { EstadoModel estadomodel = db.Estados.Find(id); db.Estados.Remove(estadomodel); db.SaveChanges(); return(RedirectToAction("Index")); }
public JsonResult EstadoPagina(int pagina, int tamPag, string filtro, string ordem) { var lista = Mapper.Map <List <EstadoViewModel> >(EstadoModel.RecuperarLista(pagina, tamPag, filtro, ordem)); var quantRegistro = EstadoModel.RecuperarQuantidade(); var quantidade = QuantidadePaginas(quantRegistro); return(Json(new { Lista = lista, Quantidade = quantidade })); }
public JsonResult RecuperarEstadosDoPais(int idPais) { var lista = Mapper.Map <List <EstadoViewModel> >(EstadoModel.RecuperarLista(idPais: idPais)); lista.Insert(0, new EstadoViewModel { Id = -1, Nome = "-- Não Selecionado --" }); return(Json(lista)); }
public UsuarioController(IUsuarioService usuarioService, ITipoUsuarioService tipoUsuarioService, IPersonalService personalService) { _usuarioService = usuarioService; _tipoUsuarioService = tipoUsuarioService; _personalService = personalService; estado = new EstadoModel(); }
public JsonResult EstadoPagina(int pagina, int tamPag, string filtro) { var lista = EstadoModel.RecuperarLista(pagina, tamPag, filtro); var difQuantPaginas = (lista.Count % ViewBag.QuantMaxLinhaPorPagina) > 0 ? 1 : 0; ViewBag.QuantPaginas = (lista.Count / ViewBag.QuantMaxLinhaPorPagina + difQuantPaginas); return(Json(lista)); }
public JsonResult RecuperarEstadosDoPais(int idPais) { var lista = Mapper.Map <List <EstadoViewModel> >(EstadoModel.RecuperarLista(idPais: idPais)); //desta forma eu estou incluindo um item na posição [0] zero do meu select lista.Insert(0, new EstadoViewModel { Id = -1, Nome = "-- Não Selecionado --" }); return(Json(lista)); }
public static bool Update(EstadoModel obj) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_update_estado"; cmd.Parameters.Add("@idestado", SqlDbType.Int).Value = obj.Idestado; cmd.Parameters.Add("@descripcion", SqlDbType.Int).Value = obj.Descripcion; return(db.ejecutarAccion(cmd)); }
// // GET: /Estado/Delete/5 public ActionResult Delete(int id = 0) { EstadoModel estadomodel = db.Estados.Find(id); if (estadomodel == null) { return(HttpNotFound()); } return(View(estadomodel)); }
public ActionResult Edit(EstadoModel estadomodel) { if (ModelState.IsValid) { db.Entry(estadomodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(estadomodel)); }
public Estado ModelToEntity(EstadoModel estado) { return(new Estado { Id = estado.Id, Nome = estado.Nome, CodigoUf = estado.CodigoUf, Regiao = estado.Regiao, Uf = estado.Uf }); }
public ActionResult Create(EstadoModel estadomodel) { if (ModelState.IsValid) { db.Estados.Add(estadomodel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(estadomodel)); }
public PersonalController(IPersonalService personalService, IAreaService areaService, ICargoService cargoService, IEmpresaService empresaService) { _personalService = personalService; _areaService = areaService; _cargoService = cargoService; _empresaService = empresaService; genero = new GeneroModel(); estado = new EstadoModel(); }
public void Insert(EstadoModel entidade) { var sql = $"INSERT INTO ESTADO (ESTUF,PAICODI,ESTCODI,ESTICMS,ESTNOME) VALUES" + $"('{entidade.ESTUF}'," + $"'{entidade.PAICODI}'," + $"'{entidade.ESTCODI}'," + $"'{entidade.ESTICMS}'," + $"'{entidade.ESTNOME}')"; ExecuteNonResult(sql); MessageBox.Show("Registro inserido com sucesso !!!"); }
public async Task <IActionResult> Create([Bind("Id,Nome,PaisId")] EstadoModel estadoModel) { if (ModelState.IsValid) { estadoModel.Nome = estadoModel.Nome.ToUpper(); _context.Add(estadoModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PaisId"] = new SelectList(_context.PaisModel, "Id", "Nome", estadoModel.PaisId); return(View(estadoModel)); }
public MunicipiosPage(EstadoModel estado) { InitializeComponent(); _estado = estado; _ibgeService = new IbgeService(); LabelEstadoNome.Text = _estado.Nome; LabelEstadoSilga.Text = _estado.Sigla; Municipios = _ibgeService.GetMunicipioFromUf(_estado.Id).OrderBy(m => m.Nome).ToList(); MunicipiosList.ItemsSource = Municipios; }
public void Update(EstadoModel entidade) { var sql = $"UPDATE ESTADO SET " + $"ESTUF = '{entidade.ESTUF}'," + $"PAICODI = '{entidade.PAICODI}'," + $"ESTCODI = '{entidade.ESTCODI}'," + $"ESTICMS = '{entidade.ESTICMS}'," + $"ESTNOME = '{entidade.ESTNOME}' " + $"WHERE ESTCODI = { entidade.ESTCODI}"; ExecuteNonResult(sql); MessageBox.Show("Registro gravado com sucesso !!!"); }
private IActionResult Salvar(EstadoModel model) { try { var estado = model.Adapt <Estado>(); _servico.Salvar(estado); _transacao.SaveChanges(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public int Salvar(EstadoModel estadoModel) { var ret = 0; var model = RecuperarPeloId(estadoModel.Id); if (model == null) { Connection(); using (SqlCommand command = new SqlCommand("INSERT INTO Estado ( Codigo, Nome, Sigla, IdPais, Ativo ) VALUES (@Codigo, @Nome, @Sigla, @IdPais, @Ativo ); select convert(int, scope_identity())", con)) { con.Open(); command.Parameters.AddWithValue("@Codigo", SqlDbType.VarChar).Value = estadoModel.Codigo; command.Parameters.AddWithValue("@Nome", SqlDbType.VarChar).Value = estadoModel.Nome; command.Parameters.AddWithValue("@Sigla", SqlDbType.VarChar).Value = estadoModel.Sigla; command.Parameters.AddWithValue("IdPais", SqlDbType.Int).Value = estadoModel.IdPais; command.Parameters.AddWithValue("@Ativo", SqlDbType.Int).Value = estadoModel.Ativo; ret = (int)command.ExecuteScalar(); } } else { Connection(); using (SqlCommand command = new SqlCommand("UPDATE Estado " + " SET Codigo=@codigo, " + " Nome=@nome, " + " Sigla=@Sigla, " + " Ativo=@ativo WHERE Id=@id ", con)) { con.Open(); command.Parameters.AddWithValue("@Codigo", SqlDbType.VarChar).Value = estadoModel.Codigo; command.Parameters.AddWithValue("@Nome", SqlDbType.VarChar).Value = estadoModel.Nome; command.Parameters.AddWithValue("@Sigla", SqlDbType.VarChar).Value = estadoModel.Sigla; command.Parameters.AddWithValue("@Ativo", SqlDbType.VarChar).Value = (estadoModel.Ativo ? 1 : 0); command.Parameters.AddWithValue("@id", SqlDbType.Int).Value = estadoModel.Id; if (command.ExecuteNonQuery() > 0) { ret = estadoModel.Id; } } } return(ret); }
private void EstadoDestinoSelecionado(object sender, EstadoModel _RegistroSelecionado) { try { if (_RegistroSelecionado != null) { cboEstadoDestino.Text = _RegistroSelecionado.NOME; Item.ESTADO_DESTINO = _RegistroSelecionado; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public async Task <IActionResult> Edit(int id, [Bind("EstadoId,Nome")] EstadoModel estadoModel) { if (id != estadoModel.EstadoId) { return(NotFound()); } if (ModelState.IsValid) { await _repositoryEstado.UpdateAsync(id, estadoModel); return(RedirectToAction(nameof(Index))); } return(View(estadoModel)); }
public ActionResult Index() { ViewBag.ListaTamPag = new SelectList(new int[] { _quantMaxLinhasPorPagina, 10, 15, 20 }, _quantMaxLinhasPorPagina); ViewBag.QuantMaxLinhasPorPagina = _quantMaxLinhasPorPagina; ViewBag.PaginaAtual = 1; var lista = EstadoModel.RecuperarLista(ViewBag.PaginaAtual, _quantMaxLinhasPorPagina); var quant = EstadoModel.RecuperarQuantidade(); var difQuantPaginas = (quant % ViewBag.QuantMaxLinhasPorPagina) > 0 ? 1 : 0; ViewBag.QuantPaginas = (quant / ViewBag.QuantMaxLinhasPorPagina) + difQuantPaginas; ViewBag.Paises = PaisModel.RecuperarLista(); return(View(lista)); }
public static EstadoModel Buscar(int id) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_buscar_estado"; cmd.Parameters.Add("@idestado", SqlDbType.Int).Value = id; DataTable dt = db.ejecutarConsulta(cmd); EstadoModel obj = new EstadoModel(); if (dt != null && dt.Rows.Count > 0) { obj.Idestado = int.Parse(dt.Rows[0]["idestado"].ToString()); obj.Descripcion = dt.Rows[0]["descripcion"].ToString(); } return(obj); }
public ActionResult Index() { ViewBag.ListaTamPag = new SelectList(new int[] { _quantMaxLinhaPorPagina, 14, 21, 28 }, _quantMaxLinhaPorPagina); ViewBag.QuantMaxLinhaPorPagina = _quantMaxLinhaPorPagina; ViewBag.PaginaAtual = 1; var lista = CidadeModel.RecuperarLista(ViewBag.PaginaAtual, _quantMaxLinhaPorPagina); var quant = CidadeModel.RecuperarQuantidadeReg(); var difQuantPaginas = (quant % ViewBag.QuantMaxLinhaPorPagina) > 0 ? 1 : 0; ViewBag.QuantPaginas = (quant / ViewBag.QuantMaxLinhaPorPagina + difQuantPaginas); ViewBag.Paises = PaisModel.RecuperarLista(1, 9999); ViewBag.Estados = EstadoModel.RecuperarLista(1, 9999); return(View(lista)); }
protected void Page_Load(object sender, EventArgs e) { if (estadoModel == null) { estadoModel = new EstadoModel(); } if (cidadeModel == null) { cidadeModel = new CidadeModel(); } if (!Page.IsPostBack) { preencherDropDownEstado(); } else { preencherDropDownCidade(); } }