public ActionResult Create([Bind(Include = "id_presentacion,nombre_presentacion,descripcion_presentacion")] presentacion presentacion) { if (ModelState.IsValid) { try { presentacion.estado = true; db.presentacion.Add(presentacion); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { VerificacionDuplicado verif = new VerificacionDuplicado(); bool rpta; rpta = verif.VerificarPresentacion(presentacion.nombre_presentacion); if (rpta == true) { ModelState.AddModelError("errorPresentacion", "Ya existe una presentacion con este nombre, agruegue uno diferente"); } else { ModelState.AddModelError("errorPresentacion", "Ocurrio un error al guadar"); } } } return(View(presentacion)); }
public JsonResult GuardarPresentacion(presentacion presentacion) { var respuesta = new ResponseModel { Respuesta = true, Redirect = "", Error = "" }; if (ModelState.IsValid) { try { presentacion.estado = true; db.presentacion.Add(presentacion); db.SaveChanges(); } catch (Exception) { VerificacionDuplicado verif = new VerificacionDuplicado(); bool rpta = verif.VerificarPresentacion(presentacion.nombre_presentacion); respuesta.Respuesta = false; if (rpta) { respuesta.Error = "Ya existe una presentacion con ese nombre"; } else { respuesta.Error = "Hubo un problema al guardar"; } } } return(Json(respuesta)); }
public ActionResult Edit([Bind(Include = "id_presentacion,nombre_presentacion,descripcion_presentacion")] presentacion presentacion) { if (ModelState.IsValid) { try { var model = db.presentacion.Where(x => x.id_presentacion == presentacion.id_presentacion).SingleOrDefault(); model.nombre_presentacion = presentacion.nombre_presentacion; model.descripcion_presentacion = presentacion.descripcion_presentacion; db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { VerificacionDuplicado verif = new VerificacionDuplicado(); bool rpta; rpta = verif.VerificarPresentacion(presentacion.nombre_presentacion); if (rpta == true) { ModelState.AddModelError("errorPresentacion", "Ya existe una presentacion con este nombre, agruegue uno diferente"); } else { ModelState.AddModelError("errorPresentacion", "Ocurrio un error al guadar"); } } } return(View(presentacion)); }
public ActionResult Changestate(int id) { int ID = id; var obtener = new presentacion(); try { obtener = db.presentacion.Where(x => x.id_presentacion == ID).SingleOrDefault(); if (obtener != null) { if (obtener.estado == true) { obtener.estado = false; db.Entry(obtener).State = EntityState.Modified; } else { obtener.estado = true; db.Entry(obtener).State = EntityState.Modified; } db.SaveChanges(); } } catch (Exception) { //throw; } return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { presentacion presentacion = db.presentacion.Find(id); db.presentacion.Remove(presentacion); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "idPresentacion,nombre,descripcion")] presentacion presentacion) { if (ModelState.IsValid) { db.Entry(presentacion).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(presentacion)); }
public ActionResult Create([Bind(Include = "idPresentacion,nombre,descripcion")] presentacion presentacion) { if (ModelState.IsValid) { db.presentacion.Add(presentacion); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(presentacion)); }
public ActionResult Edit([Bind(Include = "id,nombre,mililitros,valor_presentacion")] presentacion presentacion) { if (ModelState.IsValid) { db.editarPresentacion(presentacion.id, presentacion.nombre, presentacion.mililitros, presentacion.valor_presentacion); //db.Entry(presentacion).State = EntityState.Modified; //db.SaveChanges(); return(RedirectToAction("Index")); } return(View(presentacion)); }
public ActionResult Create([Bind(Include = "id,nombre,mililitros,valor_presentacion")] presentacion presentacion) { if (ModelState.IsValid) { //db.presentacion.Add(presentacion); //db.SaveChanges(); db.guardarPresentacion(presentacion.nombre, presentacion.mililitros, presentacion.valor_presentacion); return(RedirectToAction("Index")); } return(View(presentacion)); }
// GET: presentacions/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } presentacion presentacion = db.presentacion.Find(id); if (presentacion == null) { return(HttpNotFound()); } return(View(presentacion)); }
// GET: /Presentacion/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } presentacion presentacion = db.presentacion.Find(id); // presentacion presentacion = db.buscarProduccionV2(); if (presentacion == null) { return(HttpNotFound()); } return(View(presentacion)); }
public bool VerificarPresentacion(string par) { using (Farmacia_FarmalivioEntities contex = new Farmacia_FarmalivioEntities()) { var varCat = new presentacion(); varCat = contex.presentacion.Where(x => x.nombre_presentacion == par).SingleOrDefault(); if (varCat != null) { return(true); } else { return(false); } } }
public static List <presentacion> obtenerPresentacion(int idTipoProducto) { List <presentacion> lista = new List <presentacion>(); try { SqlCommand cmd = new SqlCommand("usp_presentacion_sel", con) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@idTipoProducto", idTipoProducto); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); presentacion p; while (dr.Read()) { p = new presentacion(); int idPresentacion = (int)dr["idPresentacion"]; string descripcion = (string)dr["descripcion"]; string imagen = (string)dr["imagen"]; p.idPresentacion = idPresentacion; p.descripcion = descripcion; p.imagen = imagen; lista.Add(p); } } catch (Exception ex) { throw ex; } finally { con.Close(); } return(lista); }