public static bool Guardar(Vendedores vendedor) { bool retorno = false; using (var conexion = new ProyectoFinalDb()) { try { if (Buscar(vendedor.VendedorId) == null) { conexion.Vendedor.Add(vendedor); } else { conexion.Entry(vendedor).State = EntityState.Modified; } conexion.SaveChanges(); retorno = true; } catch (Exception e) { MessageBox.Show(e.ToString()); } return(retorno); } }
public static bool Insertar(Productos productos) { bool obtener = false; using (var conexion = new ProyectoFinalDb()) { try { if (Buscar(productos.IdProducto) == null) { conexion.Producto.Add(productos); } else { conexion.Entry(productos).State = EntityState.Modified; } conexion.SaveChanges(); obtener = true; } catch (Exception e) { MessageBox.Show(e.ToString()); //throw; } return(obtener); } }
public static void Eliminar(Vendedores vendedor) { using (var conexion = new ProyectoFinalDb()) { try { if (vendedor != null) { conexion.Entry(vendedor).State = EntityState.Deleted; conexion.SaveChanges(); } } catch (Exception e) { MessageBox.Show(e.ToString()); throw; } } }