Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
        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 })));
        }
Ejemplo n.º 6
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            UsuarioEstabelecimento usuarioEstabelecimento = _contextDAO.GetId(id);

            if (usuarioEstabelecimento == null)
            {
                return(NotFound());
            }
            return(View(usuarioEstabelecimento));
        }
Ejemplo n.º 7
0
        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();
            }
        }