public static ClarifyDataRow[] RelatedRows(this ClarifyDataRow row, string relation) { var generic = row.ParentGeneric.ChildGenerics.Cast <ClarifyGeneric>().First(g => g.ParentRelation.InverseRelation.Name == relation); return(row.RelatedRows(generic)); }
public HistoryItemEmployee Assemble(ClarifyDataRow actEntryRecord, IHistoryContactAssembler contactAssembler) { var userRows = actEntryRecord.RelatedRows(_userGeneric); if (userRows.Length == 0) return new HistoryItemEmployee(); var userRecord = userRows[0]; var login = userRecord.AsString("login_name"); var employeeRows = userRecord.RelatedRows(_employeeGeneric); if (employeeRows.Length == 0) return new HistoryItemEmployee { Login = login }; var employeeRecord = employeeRows[0]; var name = "{0} {1}".ToFormat(employeeRecord.AsString("first_name"), employeeRecord.AsString("last_name")); var email = employeeRecord.AsString("e_mail"); var id = employeeRecord.DatabaseIdentifier(); return new HistoryItemEmployee { Name = name, Firstname = employeeRecord.AsString("first_name"), Lastname = employeeRecord.AsString("last_name"), Id = id, Login = login, Email = email, PerformedByContact = contactAssembler.Assemble(actEntryRecord) }; }
private void populateBasedOnRelatedGenerics(object dto, IEnumerable <ClarifyGenericMapEntry> childMapsForDtoType, ClarifyDataRow record) { foreach (var childMap in childMapsForDtoType.Where(map => !map.IsNewRoot())) { foreach (var childRecord in record.RelatedRows(childMap.ClarifyGeneric)) { populateDTOForGenericRecord(childMap, childRecord, dto); } } }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, object parentDto) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentDto.GetType() != child.Model.ModelType); foreach (var childMap in childMapsForChildDtos) { var parentProperty = new SingleProperty(childMap.Model.ParentProperty); var childModelType = childMap.Model.ModelType; if (typeof(IEnumerable).IsAssignableFrom(parentProperty.PropertyType)) { var propertyDTOs = new ArrayList(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); propertyDTOs.Add(propertyDTO); } parentProperty.SetValue(parentDto, propertyDTOs.ToArray(childModelType)); } else //dto is not enumerable just get the first child row { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var propertyDTO = FastYetSimpleTypeActivator.CreateInstance(childModelType); var childRecord = relatedChildRows.First(); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); parentProperty.SetValue(parentDto, propertyDTO); } else { parentProperty.SetValue(parentDto, null); } } } }
public HistoryItemContact Assemble(ClarifyDataRow actEntryRecord) { var contactRows = actEntryRecord.RelatedRows(_contactGeneric); if (contactRows.Length == 0) return null; var contactRecord = contactRows[0]; var name = "{0} {1}".ToFormat(contactRecord.AsString("first_name"), contactRecord.AsString("last_name")); var email = contactRecord.AsString("e_mail"); var id = contactRecord.DatabaseIdentifier(); return new HistoryItemContact { Name = name, Firstname = contactRecord.AsString("first_name"), Lastname = contactRecord.AsString("last_name"), Id = id, Email = email }; }
private void FillDataTable(DataSet ds, QueryProtocol queryItem, ClarifyDataRow parentClarifyRow, DataRow parentRow) { IEnumerator clarifyRowEnumerator; if (parentClarifyRow == null) { clarifyRowEnumerator = queryItem.ClarifyGeneric.Rows.GetEnumerator(); } else { clarifyRowEnumerator = parentClarifyRow.RelatedRows(queryItem.ClarifyGeneric).GetEnumerator(); } while (clarifyRowEnumerator.MoveNext()) { ClarifyDataRow clarifyRow = (ClarifyDataRow)clarifyRowEnumerator.Current; DataRow row = queryItem.ResultDataTable.NewRow(); queryItem.ResultDataTable.Rows.Add(row); for (int t = 0; t < row.Table.Columns.Count; t++) { if (row.Table.Columns[t].ColumnName == "_parentid") { row[t] = parentRow["_id"]; } else if (row.Table.Columns[t].ColumnName != "_id") { row[t] = clarifyRow[row.Table.Columns[t].ColumnName]; } } if (queryItem.ChildGenerics != null) { FillDataTables(ds, queryItem.ChildGenerics, clarifyRow, row); } } }
public HistoryItemContact Assemble(ClarifyDataRow actEntryRecord) { var contactRows = actEntryRecord.RelatedRows(_contactGeneric); if (contactRows.Length == 0) { return(null); } var contactRecord = contactRows[0]; var name = "{0} {1}".ToFormat(contactRecord.AsString("first_name"), contactRecord.AsString("last_name")); var email = contactRecord.AsString("e_mail"); var id = contactRecord.DatabaseIdentifier(); return(new HistoryItemContact { Name = name, Firstname = contactRecord.AsString("first_name"), Lastname = contactRecord.AsString("last_name"), Id = id, Email = email }); }
public HistoryItemEmployee Assemble(ClarifyDataRow actEntryRecord, IHistoryContactAssembler contactAssembler) { var userRows = actEntryRecord.RelatedRows(_userGeneric); if (userRows.Length == 0) { return(new HistoryItemEmployee()); } var userRecord = userRows[0]; var login = userRecord.AsString("login_name"); var employeeRows = userRecord.RelatedRows(_employeeGeneric); if (employeeRows.Length == 0) { return new HistoryItemEmployee { Login = login } } ; var employeeRecord = employeeRows[0]; var name = "{0} {1}".ToFormat(employeeRecord.AsString("first_name"), employeeRecord.AsString("last_name")); var email = employeeRecord.AsString("e_mail"); var id = employeeRecord.DatabaseIdentifier(); return(new HistoryItemEmployee { Name = name, Firstname = employeeRecord.AsString("first_name"), Lastname = employeeRecord.AsString("last_name"), Id = id, Login = login, Email = email, PerformedByContact = contactAssembler.Assemble(actEntryRecord) }); }
private void FillDataTable(DataSet ds, QueryProtocol queryItem, ClarifyDataRow parentClarifyRow, DataRow parentRow) { IEnumerator clarifyRowEnumerator; if (parentClarifyRow == null) { clarifyRowEnumerator = queryItem.ClarifyGeneric.Rows.GetEnumerator(); } else { clarifyRowEnumerator = parentClarifyRow.RelatedRows(queryItem.ClarifyGeneric).GetEnumerator(); } while (clarifyRowEnumerator.MoveNext()) { ClarifyDataRow clarifyRow = (ClarifyDataRow) clarifyRowEnumerator.Current; DataRow row = queryItem.ResultDataTable.NewRow(); queryItem.ResultDataTable.Rows.Add(row); for (int t = 0; t < row.Table.Columns.Count; t++) { if (row.Table.Columns[t].ColumnName == "_parentid") row[t] = parentRow["_id"]; else if (row.Table.Columns[t].ColumnName != "_id") row[t] = clarifyRow[row.Table.Columns[t].ColumnName]; } if (queryItem.ChildGenerics != null) FillDataTables(ds, queryItem.ChildGenerics, clarifyRow, row); } }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, ModelData parentModel) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentModel.Name != child.Model.ModelName); foreach (var childMap in childMapsForChildDtos) { if (childMap.Model.IsCollection) { var children = new List <ModelData>(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, childRecord, childModel); if (!childModel.IsEmpty()) { children.Add(childModel); } } parentModel[childMap.Model.ParentProperty] = children; } else if (parentGenericMap.ClarifyGeneric == childMap.ClarifyGeneric) { var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, parentRecord, childModel); if (!childModel.IsEmpty()) { parentModel[childMap.Model.ParentProperty] = childModel; } else if (childMap.Model.AllowEmpty) { parentModel[childMap.Model.ParentProperty] = null; } } else { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var childRecord = relatedChildRows.First(); var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, childRecord, childModel); if (!childModel.IsEmpty()) { parentModel[childMap.Model.ParentProperty] = childModel; } else if (childMap.Model.AllowEmpty) { parentModel[childMap.Model.ParentProperty] = null; } } else { parentModel[childMap.Model.ParentProperty] = null; } } } }