Esempio n. 1
0
        public ActionResult Create([Bind(Include = "id,nombre")] tipo_lecheria tipo_lecheria)
        {
            if (ModelState.IsValid)
            {
                bool f = false;
                tipo_lecheria.nombre = tipo_lecheria.nombre.ToUpperInvariant();
                var tipo_lecherias = db.tipo_lecheria.Select(a => a.nombre);
                foreach (var a in tipo_lecherias)
                {
                    if (a == tipo_lecheria.nombre)
                    {
                        ViewBag.Error = "Tipo de lecheria ya existe";
                        f             = true;
                    }
                }
                if (f == true)
                {
                    return(View(tipo_lecheria));
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        db.tipo_lecheria.Add(tipo_lecheria);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
            }


            return(View(tipo_lecheria));
        }
Esempio n. 2
0
        // GET: Tipo_lecheria/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tipo_lecheria tipo_lecheria = db.tipo_lecheria.Find(id);

            if (tipo_lecheria == null)
            {
                return(HttpNotFound());
            }
            return(View(tipo_lecheria));
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            tipo_lecheria tipo_lecheria = db.tipo_lecheria.Find(id);

            try
            {
                db.tipo_lecheria.Remove(tipo_lecheria);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Error = "No se puede eliminar debido a que existen datos asociados";
            }
            return(View(tipo_lecheria));
        }