Пример #1
0
 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));
 }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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"));
        }
Пример #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            presentacion presentacion = db.presentacion.Find(id);

            db.presentacion.Remove(presentacion);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #6
0
 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));
 }
Пример #7
0
        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));
        }
Пример #8
0
 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));
 }
Пример #9
0
        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));
        }
Пример #10
0
        // 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));
        }
Пример #11
0
        // 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));
        }
Пример #12
0
 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);
         }
     }
 }
Пример #13
0
        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);
        }