1- using System . Collections ;
21using System . Collections . Generic ;
32using System . Linq ;
4- using System . Reflection ;
53using System . Threading . Tasks ;
64using JsonApiDotNetCore . Extensions ;
75using JsonApiDotNetCore . Models ;
@@ -18,10 +16,17 @@ public GenericProcessor(DbContext context)
1816 }
1917
2018 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 )
2126 {
2227 var relationshipType = relationship . Type ;
2328
24- if ( relationship . IsHasMany )
29+ if ( relationship . IsHasMany )
2530 {
2631 var entities = _context . GetDbSet < T > ( ) . Where ( x => relationshipIds . Contains ( x . StringId ) ) . ToList ( ) ;
2732 relationship . SetValue ( parent , entities ) ;
@@ -30,9 +35,7 @@ public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute
3035 {
3136 var entity = _context . GetDbSet < T > ( ) . SingleOrDefault ( x => relationshipIds . First ( ) == x . StringId ) ;
3237 relationship . SetValue ( parent , entity ) ;
33- }
34-
35- await _context . SaveChangesAsync ( ) ;
38+ }
3639 }
3740 }
3841}
0 commit comments