File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
src/SimpleToDoService/Database Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -93,15 +93,16 @@ public Task CreateTask(Task task)
9393
9494 var entity = context . Tasks . Add ( task ) ;
9595
96- foreach ( var tsk in context . Tasks . Where ( o => o . TaskPrototypeUuid == task . TaskPrototypeUuid && o . Completed == false ) )
97- {
98- tsk . Completed = true ;
99- }
96+ var tasksToComplete = context . Tasks . Where ( o => o . TaskPrototypeUuid == task . TaskPrototypeUuid && o . Completed == false ) . ToList ( ) ;
97+ tasksToComplete . ForEach ( o => o . Completed = true ) ;
10098
10199 try
102100 {
103101 if ( context . SaveChanges ( ) > 0 )
102+ {
103+ tasksToComplete . ForEach ( o => context . Entry ( o ) . State = EntityState . Detached ) ;
104104 return entity . Entity ;
105+ }
105106 }
106107 catch ( DbUpdateException ex )
107108 {
@@ -115,14 +116,18 @@ public Task CreateTask(Task task)
115116 entity = context . Tasks . Add ( task ) ;
116117
117118 if ( context . SaveChanges ( ) > 0 )
119+ {
120+ tasksToComplete . ForEach ( o => context . Entry ( o ) . State = EntityState . Detached ) ;
118121 return entity . Entity ;
122+ }
119123 }
120124 else
121125 {
122126 throw ;
123127 }
124128 }
125129
130+ tasksToComplete . ForEach ( o => context . Entry ( o ) . State = EntityState . Detached ) ;
126131 return null ;
127132 }
128133
You can’t perform that action at this time.
0 commit comments