public OperationResult BulkDelete <T>(T entity, Guid idToRemove, int timeOut = 20000, string connectionStringName = "Sys10Context") { using (var connection = new Sys10Database(connectionStringName, timeOut).Connection) { connection.Open(); var sqlTransaction = connection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted); var tableName = ((IModelBase)entity).TableName; var primaryKey = ((IModelBase)entity).PrimaryKey; OperationResult operationResult; var count = 0; operationResult = DeleteByIdsUsingDataTableWithTransaction(primaryKey, new[] { idToRemove }.ToList(), tableName, sqlTransaction); if (operationResult.Success) { sqlTransaction.Commit(); } else if (sqlTransaction != null) { sqlTransaction.Rollback(); } return(operationResult); } }
public OperationResult BulkEditRange <T>(IEnumerable <T> entities, int timeOut = 20000, string connectionStringName = "Sys10Context") { if (!entities.Any()) { return new OperationResult() { Message = "Lista vazia", Success = true } } ; var tableName = ((IModelBase)entities.First()).TableName; var primaryKey = ((IModelBase)entities.First()).PrimaryKey; using (var connection = new Sys10Database(connectionStringName, timeOut).Connection) { connection.Open(); var sqlTransaction = connection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted); try { OperationResult operationResult; var entityDatatable = entities.ToList().ToDataTable(tableName, new[] { primaryKey }); operationResult = UpdateUsingDataTableWithTransaction(entityDatatable, sqlTransaction); if (operationResult.Success) { sqlTransaction.Commit(); } else if (sqlTransaction != null) { sqlTransaction.Rollback(); } return(operationResult); } catch (Exception ex) { if (sqlTransaction != null) { sqlTransaction.Rollback(); } return(new OperationResult(false, ex.Message)); } } }
public OperationResult BulkDeleteRange <T>(IEnumerable <T> entities, List <Guid> idsToRemove, int timeOut = 20000, string connectionStringName = "Sys10Context") { if (!entities.Any()) { return new OperationResult() { Message = "Lista vazia", Success = true } } ; using (var connection = new Sys10Database(connectionStringName, timeOut).Connection) { connection.Open(); var sqlTransaction = connection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted); if (!entities.Any()) { return new OperationResult() { Message = "Lista vazia", Success = true } } ; var tableName = ((IModelBase)entities.First()).TableName; var primaryKey = ((IModelBase)entities.First()).PrimaryKey; OperationResult operationResult; var count = 0; operationResult = DeleteByIdsUsingDataTableWithTransaction(primaryKey, idsToRemove, tableName, sqlTransaction); if (operationResult.Success) { sqlTransaction.Commit(); } else if (sqlTransaction != null) { sqlTransaction.Rollback(); } return(operationResult); } }