protected override EntityWriter <Departamento> GetWriter(EntityState status) { EntityWriter <Departamento> writer = null; // select Writer switch (status) { case EntityState.Added: writer = new DepartamentoInsert(); break; case EntityState.Modified: writer = new DepartamentoUpdate(); break; case EntityState.Deleted: writer = new DepartamentoDelete(); break; case EntityState.Unchanged: default: break; } return(writer); }
protected override EntityWriter <T> GetWriter(EntityState status) { EntityWriter <T> writer = null; // select Writer switch (status) { case EntityState.Added: writer = GetInsertWriter; break; case EntityState.Modified: writer = GetUpdateWriter; break; case EntityState.Deleted: writer = GetDeleteWriter; break; case EntityState.Unchanged: default: break; } return(writer); }
public bool Write(Collection <T> collection) { // entidades a ser eliminadas Collection <T> deleteColl = new Collection <T>(); // crear conexion y comenzar transaccion IDbTransaction transaction; IDbConnection connection = Connection.GetConnection(); connection.Open(); transaction = connection.BeginTransaction(); try { foreach (T entity in collection) { EntityWriter <T> writer = GetWriter((entity as IEntity).State); if (writer != null) { writer.Entity = entity; writer.Connection = connection; writer.Transaction = transaction; writer.Execute(); } // Detectar Delete y almacenar entidad en coleccion para eliminar if ((entity as IEntity).State == EntityState.Deleted) { deleteColl.Add(entity); } } transaction.Commit(); // Eliminar entidades if (deleteColl.Count > 0) { foreach (var item in deleteColl) { collection.Remove(item); } deleteColl.Clear(); } return(true); } catch (Exception) { transaction.Rollback(); //throw; // log details return(false); } finally { connection.Close(); } }
protected override EntityWriter <ClaveMes> GetWriter(EntityState status) { EntityWriter <ClaveMes> writer = null; // select Writer switch (status) { case EntityState.Added: writer = new ClaveMesInsert(); break; case EntityState.Modified: writer = new ClaveMesUpdate(); break; case EntityState.Deleted: writer = new ClaveMesDelete(); break; case EntityState.Unchanged: default: break; } return(writer); }
public bool Write(T entity) { // crear conexion y comenzar transaccion IDbTransaction transaction; IDbConnection connection = Connection.GetConnection(); connection.Open(); transaction = connection.BeginTransaction(); try { EntityWriter <T> writer = GetWriter((entity as IEntity).State); if (writer != null) { writer.Entity = entity; writer.Connection = connection; writer.Transaction = transaction; writer.Execute(); (entity as IEntity).State = EntityState.Unchanged; } transaction.Commit(); return(true); } catch (Exception) { transaction.Rollback(); //throw; // log details return(false); } finally { connection.Close(); } }