Exemplo n.º 1
0
        public List<ClienteBEAN> listaClientes()
        {
            //CREATE PROCEDURE SP_CATEGORIA_List
            //as
            //select idCategoria, nombreCategoria
            //from tb_Categoria

            List<ClienteBEAN> lista = new List<ClienteBEAN>();
            SqlCommand cmd = new SqlCommand();
            SqlDataReader lector;
            ClienteBEAN clienBEAN;
            try
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "";
                cmd.Connection = BD_ExamenFinalEntities.GetConnection();
                lector = cmd.ExecuteReader();
                while (lector.Read())
                {
                    clienBEAN = new ClienteBEAN();
                    clienBEAN.Cliente = lector.GetInt32(0);
                    clienBEAN.TipoAtencion = lector.GetString(1);
                    lista.Add(clienBEAN);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return lista;
        }
 // GET: Cliente
 public ActionResult Index()
 {
     try
     {
         List <tbCliente> listaCliente;
         using (var db = new BD_ExamenFinalEntities())
         {
             listaCliente = db.tbCliente.ToList();
             return(View(listaCliente));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult Agregar(tbCliente clien)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                using (var db = new BD_ExamenFinalEntities())
                {
                    clien.Estado = "A";
                    db.tbCliente.Add(clien);
                    db.SaveChanges();
                    return(RedirectToAction("ListaClientes"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);
                //throw;
                return(View());
            }
        }