@@ -24,15 +24,28 @@ public static Type GetTypeFromModelRelationshipName(Type modelType, string relat
24
24
25
25
public static object SetValuesOnModelInstance ( object model , Dictionary < string , object > jsonApiAttributes , Dictionary < string , object > jsonApiRelationships )
26
26
{
27
- var modelProperties = model . GetType ( ) . GetProperties ( ) . ToList ( ) ;
27
+ var patches = GetEntityPatch ( model . GetType ( ) , jsonApiAttributes , jsonApiRelationships ) ;
28
+ foreach ( var patch in patches )
29
+ {
30
+ patch . Key . SetValue ( model , patch . Value ) ;
31
+ }
32
+
33
+ return model ;
34
+ }
35
+
36
+ public static Dictionary < PropertyInfo , object > GetEntityPatch ( Type modelType , Dictionary < string , object > jsonApiAttributes , Dictionary < string , object > jsonApiRelationships )
37
+ {
38
+ var patchDefinitions = new Dictionary < PropertyInfo , object > ( ) ;
39
+
40
+ var modelProperties = modelType . GetProperties ( ) . ToList ( ) ;
28
41
foreach ( var attribute in jsonApiAttributes )
29
42
{
30
43
modelProperties . ForEach ( pI =>
31
44
{
32
45
if ( pI . Name . ToProperCase ( ) == attribute . Key . ToProperCase ( ) )
33
46
{
34
47
var convertedValue = Convert . ChangeType ( attribute . Value , pI . PropertyType ) ;
35
- pI . SetValue ( model , convertedValue ) ;
48
+ patchDefinitions . Add ( pI , convertedValue ) ;
36
49
}
37
50
} ) ;
38
51
}
@@ -49,13 +62,13 @@ public static object SetValuesOnModelInstance(object model, Dictionary<string, o
49
62
if ( pI . Name . ToProperCase ( ) == relationshipPropertyName . ToProperCase ( ) )
50
63
{
51
64
var convertedValue = Convert . ChangeType ( relationshipId , pI . PropertyType ) ;
52
- pI . SetValue ( model , convertedValue ) ;
65
+ patchDefinitions . Add ( pI , convertedValue ) ;
53
66
}
54
67
} ) ;
55
68
}
56
69
}
57
70
58
- return model ;
71
+ return patchDefinitions ;
59
72
}
60
73
}
61
74
}
0 commit comments