private static Type GetJsonModelType(BaseDbEntity entity) { Type jsonEntityType = null; MapToType mapToAttr = entity.GetType().GetCustomAttribute(typeof(MapToType)) as MapToType; if (mapToAttr != null) { jsonEntityType = mapToAttr.JsonEntityType; } return jsonEntityType; }
public static IJsonEntity Convert(BaseDbEntity entity) { IJsonEntity newJsonEntity = null; Type jsonEntityType = GetJsonModelType(entity); if (jsonEntityType != null) { newJsonEntity = Activator.CreateInstance(jsonEntityType) as IJsonEntity; FillJsonEntity(entity, newJsonEntity); } return newJsonEntity; }
private static List<MapToField> GetMappedFields(BaseDbEntity entity) { List<MapToField> mappedFields = new List<MapToField>(); List<PropertyInfo> properties = entity.GetType().GetProperties().ToList(); properties.ForEach(property => { MapToField mapToAttr = property.GetCustomAttribute(typeof (MapToField)) as MapToField; if (mapToAttr != null) { mappedFields.Add(mapToAttr); } }); return mappedFields; }
private static void FillJsonEntity(BaseDbEntity entity, IJsonEntity newJsonEntity) { List<MapToField> mappedFields = GetMappedFields(entity); Type jsonEntityType = newJsonEntity.GetType(); Type dbEntityType = entity.GetType(); mappedFields.ForEach(mappedAttr => { var jsonEntityProp = jsonEntityType.GetProperty(mappedAttr.JsonModelField); var dbEntityProp = dbEntityType.GetProperty(mappedAttr.JsonModelField); if (jsonEntityProp != null && dbEntityProp != null) { var dbValue = dbEntityProp.GetValue(entity); jsonEntityProp.SetValue(newJsonEntity, dbValue); } }); }
protected async Task AuditLog(int currentUserId, BaseDbEntity newObject, string priorObjectSerialized) { await AuditLog(currentUserId, newObject.Id, newObject, priorObjectSerialized, true); }
protected async Task AuditLog(int currentUserId, BaseDbEntity newObject, BaseDbEntity priorObject) { await AuditLog(currentUserId, newObject.Id, newObject, priorObject); }