public IEnumerable <UsuarioEstabelecimento> GetAllEstabelecimentos() { List <UsuarioEstabelecimento> listaUsuarioEstabelecimento = new List <UsuarioEstabelecimento>(); using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("stp_Estabelecimento_Sel", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = 60 }; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { UsuarioEstabelecimento usuarioEstabelecimento = new UsuarioEstabelecimento { IdEstabelecimento = Convert.ToInt32(rdr["IdEstabelecimento"]), NomeEstabelecimento = rdr["NomeEstabelecimento"].ToString() }; listaUsuarioEstabelecimento.Add(usuarioEstabelecimento); } con.Close(); } return(listaUsuarioEstabelecimento); }
public UsuarioEstabelecimento GetId(int?id) { UsuarioEstabelecimento usuarioEstabelecimento = new UsuarioEstabelecimento(); using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("stp_UsuarioEstabelecimento_Sel", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = 60 }; cmd.Parameters.AddWithValue("@IdUsuarioEstabelecimento", id); cmd.Parameters.AddWithValue("@TipoConsulta", "PorIdUsuarioEstabelecimento"); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { usuarioEstabelecimento.IdUsuario = Convert.ToInt32(rdr["IdUsuario"]); usuarioEstabelecimento.IdEstabelecimento = Convert.ToInt32(rdr["IdEstabelecimento"]); usuarioEstabelecimento.NomeEstabelecimento = rdr["NomeEstabelecimento"].ToString(); usuarioEstabelecimento.IdUsuarioEstabelecimento = Convert.ToInt32(rdr["IdOperadorEstabelecimento"]); } } return(usuarioEstabelecimento); }
public IActionResult Create([FromForm] UsuarioEstabelecimento usuarioEstabelecimento) { if (ModelState.IsValid) { _contextDAO.Add(usuarioEstabelecimento); return(RedirectToAction("Index", new RouteValueDictionary( new { action = "Index", Id = usuarioEstabelecimento.IdUsuario }))); } return(View(usuarioEstabelecimento)); }
public IActionResult Edit(int id, [Bind] UsuarioEstabelecimento usuarioEstabelecimento) { if (id != usuarioEstabelecimento.IdUsuario) { return(NotFound()); } if (ModelState.IsValid) { _contextDAO.Edit(usuarioEstabelecimento); return(RedirectToAction("Index")); } return(View(usuarioEstabelecimento)); }
public IActionResult Delete(int?id) { UsuarioEstabelecimento usuarioEstabelecimento = _contextDAO.GetId(id); if (usuarioEstabelecimento == null) { return(NotFound()); } _contextDAO.Delete(id); return(RedirectToAction("Index", new RouteValueDictionary( new { action = "Index", Id = usuarioEstabelecimento.IdUsuario }))); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } UsuarioEstabelecimento usuarioEstabelecimento = _contextDAO.GetId(id); if (usuarioEstabelecimento == null) { return(NotFound()); } return(View(usuarioEstabelecimento)); }
public void Add(UsuarioEstabelecimento usuarioEstabelecimento) { using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("stp_UsuarioEstabelecimento_Ins", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = 60 }; cmd.Parameters.AddWithValue("@IdEstabelecimento", usuarioEstabelecimento.IdEstabelecimento); cmd.Parameters.AddWithValue("@IdUsuario", usuarioEstabelecimento.IdUsuario); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }