1
- using System . Collections ;
2
1
using System . Collections . Generic ;
3
2
using System . Linq ;
4
- using System . Reflection ;
5
3
using System . Threading . Tasks ;
6
4
using JsonApiDotNetCore . Extensions ;
7
5
using JsonApiDotNetCore . Models ;
@@ -18,10 +16,17 @@ public GenericProcessor(DbContext context)
18
16
}
19
17
20
18
public async Task UpdateRelationshipsAsync ( object parent , RelationshipAttribute relationship , IEnumerable < string > relationshipIds )
19
+ {
20
+ SetRelationships ( parent , relationship , relationshipIds ) ;
21
+
22
+ await _context . SaveChangesAsync ( ) ;
23
+ }
24
+
25
+ public void SetRelationships ( object parent , RelationshipAttribute relationship , IEnumerable < string > relationshipIds )
21
26
{
22
27
var relationshipType = relationship . Type ;
23
28
24
- if ( relationship . IsHasMany )
29
+ if ( relationship . IsHasMany )
25
30
{
26
31
var entities = _context . GetDbSet < T > ( ) . Where ( x => relationshipIds . Contains ( x . StringId ) ) . ToList ( ) ;
27
32
relationship . SetValue ( parent , entities ) ;
@@ -30,9 +35,7 @@ public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute
30
35
{
31
36
var entity = _context . GetDbSet < T > ( ) . SingleOrDefault ( x => relationshipIds . First ( ) == x . StringId ) ;
32
37
relationship . SetValue ( parent , entity ) ;
33
- }
34
-
35
- await _context . SaveChangesAsync ( ) ;
38
+ }
36
39
}
37
40
}
38
41
}
0 commit comments