@@ -188,7 +188,7 @@ public static ApiResponse<FoodEntry> CreateFoodEntry(User user, FoodEntry food)
188188 } ;
189189 }
190190 food . Food = foundFood ;
191- User ? foundPayedBy = a . Users . FirstOrDefault ( x => x . Id == food . PayedBy . Id ) ;
191+ User ? foundPayedBy = a . Users . FirstOrDefault ( x => x . Id == food . PayedBy ? . Id ) ;
192192 if ( foundPayedBy == null )
193193 {
194194 return new ApiResponse < FoodEntry >
@@ -308,6 +308,7 @@ public static ApiResponse<Ingredient> CreateIngredient(User user, Ingredient ing
308308 public static ApiResponse DeleteAssembly ( User user , string Id )
309309 {
310310 using var d = new AppDbContext ( ) ;
311+ d . Attach ( user ) ;
311312 var assembly = d . Assemblies . FirstOrDefault ( a => a . Id == Id ) ;
312313 if ( assembly == null )
313314 {
@@ -345,7 +346,8 @@ static bool CanAdministrateAssembly(User user, Assembly assembly)
345346 public static ApiResponse DeleteIngredient ( User user , string id )
346347 {
347348 using var d = new AppDbContext ( ) ;
348- var ingredient = d . Ingredients . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . FirstOrDefault ( ) ;
349+ d . Attach ( user ) ;
350+ var ingredient = d . Ingredients . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . ThenInclude ( x => x . Admins ) . FirstOrDefault ( ) ;
349351 if ( ingredient == null )
350352 {
351353 return new ApiResponse
@@ -376,7 +378,8 @@ public static ApiResponse DeleteIngredient(User user, string id)
376378 public static ApiResponse DeleteFoodEntry ( User user , string id )
377379 {
378380 using var d = new AppDbContext ( ) ;
379- var foodEntry = d . FoodEntries . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . FirstOrDefault ( ) ;
381+ d . Attach ( user ) ;
382+ var foodEntry = d . FoodEntries . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . ThenInclude ( x => x . Admins ) . FirstOrDefault ( ) ;
380383 if ( foodEntry == null )
381384 {
382385 return new ApiResponse
@@ -564,7 +567,8 @@ public static ApiResponse<String> RemoveUserFromAssembly(User user, string assem
564567 public static ApiResponse DeleteFood ( User user , string id )
565568 {
566569 using var d = new AppDbContext ( ) ;
567- var food = d . Foods . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . FirstOrDefault ( ) ;
570+ d . Attach ( user ) ;
571+ var food = d . Foods . Where ( a => a . Id == id ) . Include ( x => x . Assembly ) . ThenInclude ( x => x . Admins ) . FirstOrDefault ( ) ;
568572 if ( food == null )
569573 {
570574 return new ApiResponse
@@ -574,7 +578,7 @@ public static ApiResponse DeleteFood(User user, string id)
574578 } ;
575579 }
576580
577- if ( ! CanAdministrateAssembly ( user , food . Assembly ) )
581+ if ( ! CanAdministrateAssembly ( user , food . Assembly ) && food . CreatedBy . Id != user . Id )
578582 {
579583 return new ApiResponse
580584 {
@@ -589,7 +593,7 @@ public static ApiResponse DeleteFood(User user, string id)
589593
590594 return new ApiResponse
591595 {
592- Success = true
596+ Success = true ,
593597 } ;
594598 }
595599
0 commit comments