Beispiel #1
0
        /// <summary>
        /// Obtiene un objeto ProductoPromocion específico.
        /// </summary>
        /// <param name="id">Parámetro de búsqueda.</param>
        /// <returns>El objeto encontrado.</returns>
        public ProductoPromocion obtener(int id)
        {
            ProductoPromocion detalle = new ProductoPromocion();

            try{
                using (bdsharkEntities db = new bdsharkEntities())
                {
                    detalle = db.ProductoPromocion.Find(id);
                }
            }catch (Exception ex) {
                MessageBox.Show("Error: " + ex + "\nError en la autenticación con la base de datos", "Aviso Shark");
            }
            return(detalle);
        }
Beispiel #2
0
 /// <summary>
 /// Registra un objeto ProductoPromcion en la base de datos.
 /// </summary>
 /// <param name="detalle">el objeto a registrar.</param>
 public void registrar(ProductoPromocion detalle)
 {
     try{
         using (bdsharkEntities db = new bdsharkEntities())
         {
             db.Configuration.LazyLoadingEnabled = true;
             db.Productos.Attach(detalle.Producto);
             db.Promociones.Attach(detalle.Promocion);
             db.ProductoPromocion.Add(detalle);
             db.SaveChanges();
         }
     }catch (Exception ex) {
         MessageBox.Show("Error: " + ex + "\nError en la autenticación con la base de datos", "Aviso Shark");
     }
 }
Beispiel #3
0
        /// <summary>
        /// Modifíca un objeto producto en la base de datos.
        /// </summary>
        /// <param name="detalle">El objeto a modificar.</param>
        public void modificar(ProductoPromocion detalle)
        {
            try{
                using (bdsharkEntities db = new bdsharkEntities())
                {
                    ProductoPromocion n_detalle = db.ProductoPromocion.Find(detalle.id);
                    n_detalle.cantidad     = detalle.cantidad;
                    n_detalle.producto_id  = detalle.producto_id;
                    n_detalle.promocion_id = detalle.promocion_id;

                    db.Entry(n_detalle).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }catch (Exception ex) {
                MessageBox.Show("Error: " + ex + "\nError en la autenticación con la base de datos", "Aviso Shark");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Elimina un objeto ProductoPromocion en la base de datos.
        /// </summary>
        /// <param name="_detalle">El objeto a eliminar.</param>
        public void eliminar(ProductoPromocion _detalle)
        {
            try{
                using (bdsharkEntities db = new bdsharkEntities())
                {
                    var Query = from detalle in db.ProductoPromocion where detalle.id == _detalle.id select detalle;

                    foreach (var detalle in Query)
                    {
                        db.Entry(detalle).State = EntityState.Deleted;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex + "\nError en la autenticación con la base de datos", "Aviso Shark");
            }
        }