mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 08:10:07 +01:00
fix: remove references to deleted images from quotes
This commit is contained in:
@@ -189,6 +189,18 @@ public class UserContentController : ControllerBase
|
||||
}
|
||||
|
||||
// - from db
|
||||
// - first, from any quotes that reference it
|
||||
List<Quote> quotesToModify = await _db.Quotes
|
||||
.Include(q => q.Image)
|
||||
.Where(q => q.Image == image)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (Quote quote in quotesToModify)
|
||||
{
|
||||
quote.Image = null;
|
||||
}
|
||||
|
||||
// - finally, from images table
|
||||
_db.Images.Remove(image);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user