public static void CreateEntity <T>(T entity) where T : class, IRepositoryEntity, IRepositoryCreatedEntity, new() { var entityDbName = entity.GetTableName(); var idFieldName = entity.GetIdFieldName(); var fields = entity.GetFieldNames(); var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite); source.Select(fields); source.SetWhere(idFieldName, IMRecordset.Operation.Eq, -1); using (source.OpenWithScope()) { source.AddNew(); entity.SaveToRecordset(source); source.Update(); } }
public static int GetCurrentUserId() { var result = IM.NullI; string userName = IM.ConnectedUser(); var employeeRs = new IMRecordset(Employee.TableName, IMRecordset.Mode.ReadOnly); employeeRs.Select(Employee.Fields.Id); employeeRs.SetWhere(Employee.Fields.AppUser, IMRecordset.Operation.Eq, userName); using (employeeRs.OpenWithScope()) { if (!employeeRs.IsEOF()) { result = employeeRs.GetI(Employee.Fields.Id); } } return(result); }
public static void UpdateEntity <T>(T entity) where T : class, IRepositoryEntity, IRepositoryUpdatedEntity, new() { var entityDbName = entity.GetTableName(); var idFieldName = entity.GetIdFieldName(); var fields = entity.GetFieldNames(); var id = entity.GetId(); var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite); source.Select(fields); source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString()); using (source.OpenWithScope()) { if (source.IsEOF()) { throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}"); } source.Edit(); entity.SaveToRecordset(source); source.Update(); } }
public static T ReadEntityById <T>(int id) where T : class, IRepositoryEntity, IRepositoryReadedEntity, new() { var entity = new T(); var entityDbName = entity.GetTableName(); var idFieldName = entity.GetIdFieldName(); var fields = entity.GetFieldNames(); var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly); source.Select(fields); source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString()); using (source.OpenWithScope()) { if (source.IsEOF()) { throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}"); } entity.LoadFromRecordset(source); } return(entity); }
public static OpenedRecordsetScope OpenForAdd(this IMRecordset recordset, params string[] fields) { recordset.Select(string.Join(",", fields)); recordset.SetWhere(fields[0], IMRecordset.Operation.Eq, -1); return(recordset.OpenWithScope()); }