public TipoIngrediente FindById(int?id)
        {
            TipoIngrediente tpingrediente = null;

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("select*from TipoIngrediente where CTipoIngrediente='" + id + "'", con);
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            tpingrediente = new TipoIngrediente();
                            tpingrediente.CTipoIngrediente = Convert.ToInt32(dr["CTipoIngrediente"]);
                            tpingrediente.NTipoIngrediente = dr["NTipoIngrediente"].ToString();
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(tpingrediente);
        }
Exemple #2
0
        public bool Update(Ingrediente t)
        {
            TipoIngrediente tpingrediente = tpingredienteRepository.FindById(t.CTipoIngrediente.CTipoIngrediente);

            t.CTipoIngrediente = tpingrediente;
            return(ingredienteRepository.Update(t));
        }
        public List <TipoIngrediente> FindAll()
        {
            var tipos = new List <TipoIngrediente>();

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("select*from TipoIngrediente", con);
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var tpingrediente = new TipoIngrediente();
                            tpingrediente.CTipoIngrediente = Convert.ToInt32(dr["CTipoIngrediente"]);
                            tpingrediente.NTipoIngrediente = dr["NTipoIngrediente"].ToString();
                            tipos.Add(tpingrediente);
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(tipos);
        }
Exemple #4
0
        public bool Insert(Ingrediente t)
        {
            TipoIngrediente tpingrediente = tpingredienteRepository.FindById(t.CTipoIngrediente.CTipoIngrediente);

            t.CTipoIngrediente = tpingrediente;
            return(ingredienteRepository.Insert(t));
        }
Exemple #5
0
        public Ingrediente FindById(int?id)
        {
            Ingrediente ingrediente = null;

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("select ig.CIngrediente, ig.NIngrediente, ig.QUnidadMedidaIngrediente, ig.NUnidadMedidaIngrediente, tp.NTipoIngrediente from Ingrediente ig, TipoIngrediente tp where ig.CTipoIngrediente=tp.CTipoIngrediente and ig.CIngrediente='" + id + "'", con);
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            ingrediente = new Ingrediente();
                            var tipo = new TipoIngrediente();
                            ingrediente.CIngrediente             = Convert.ToInt32(dr["CIngrediente"]);
                            ingrediente.NIngrediente             = dr["NIngrediente"].ToString();
                            ingrediente.QUnidadMedidaIngrediente = Convert.ToInt32(dr["QUnidadMedidaIngrediente"]);
                            ingrediente.NUnidadMedidaIngrediente = dr["NUnidadMedidaIngrediente"].ToString();
                            tipo.NTipoIngrediente        = dr["NTipoIngrediente"].ToString();
                            ingrediente.CTipoIngrediente = tipo;
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(ingrediente);
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            TipoIngrediente tpingrediente = tpingredienteService.FindById(id);

            return(View(tpingrediente));
        }
        public ActionResult Create(TipoIngrediente tpingrediente)
        {
            bool rpta = tpingredienteService.Insert(tpingrediente);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public ActionResult Edit(TipoIngrediente tpingrediente)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            bool rpta = tpingredienteService.Update(tpingrediente);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public bool Insert(TipoIngrediente t)
        {
            bool rpta = false;

            try
            {
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_Pizza"].ToString()))
                {
                    con.Open();
                    var cmd = new SqlCommand("insert into TipoIngrediente values(@nombre)", con);
                    cmd.Parameters.AddWithValue("@nombre", t.NTipoIngrediente);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    rpta = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rpta);
        }
 public bool Update(TipoIngrediente t)
 {
     return(tpingredienteRepository.Update(t));
 }
 public bool Insert(TipoIngrediente t)
 {
     return(tpingredienteRepository.Insert(t));
 }