public bool Update() { try { Datos.TIPO_PRODUCTO tipo_producto = Conexion.ModeloEntities.TIPO_PRODUCTO.First(e => e.ID == ID); //aqui usamos lambda tipo_producto.ID = ID; tipo_producto.NOMBRE = NOMBRE; Conexion.ModeloEntities.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool Read() { try { Datos.TIPO_PRODUCTO tipo_producto = (from fam in Conexion.ModeloEntities.TIPO_PRODUCTO where fam.ID == ID select fam).First(); ID = tipo_producto.ID; NOMBRE = tipo_producto.NOMBRE; //si no lo encuentra el resultado sera null return(true); } catch (Exception) { return(false); } }
/// <summary> /// Lee un registro de proveedor en la BBDD /// </summary> /// <returns></returns> public bool Read() { Datos.FerreteriaFermeEntities bbdd = new Datos.FerreteriaFermeEntities(); try { /* Se obtiene el primer registro coincidente con el id */ Datos.TIPO_PRODUCTO tip = bbdd.TIPO_PRODUCTO.First(e => e.ID_TIPO == ID_TIPO); /* Se copian las propiedades de datos al negocio */ CommonBC.Syncronize(tip, this); return(true); } catch (Exception ex) { return(false); } }
//Agregar public bool Create() { Datos.FerreteriaFermeEntities bbdd = new Datos.FerreteriaFermeEntities(); Datos.TIPO_PRODUCTO tip = new Datos.TIPO_PRODUCTO(); try { CommonBC.Syncronize(this, tip); bbdd.TIPO_PRODUCTO.Add(tip); bbdd.SaveChanges(); return(true); } catch (Exception ex) { bbdd.TIPO_PRODUCTO.Remove(tip); return(false); } }
/// <summary> /// Elimina un registro de proveedor en la BBDD /// </summary> /// <returns></returns> public bool Delete() { Datos.FerreteriaFermeEntities bbdd = new Datos.FerreteriaFermeEntities(); try { /* Se obtiene el primer registro coincidente con el id */ Datos.TIPO_PRODUCTO tip = bbdd.TIPO_PRODUCTO.First(e => e.ID_TIPO == ID_TIPO); /* Se elimina el registro del EDM */ bbdd.TIPO_PRODUCTO.Remove(tip); bbdd.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool Create() { try { //objeto que entra en la base de datos Datos.TIPO_PRODUCTO tipo_producto = new Datos.TIPO_PRODUCTO() { ID = ID, NOMBRE = NOMBRE }; Conexion.ModeloEntities.TIPO_PRODUCTO.Add(tipo_producto); Conexion.ModeloEntities.SaveChanges(); //abre la conexion, hace el comando sql, actualiza la BD, cierra la conexion return(true); } catch (Exception) { return(false); } }