mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-15 08:30:06 +01:00
Compare commits
2 Commits
12f489749a
...
8324ba8456
| Author | SHA1 | Date | |
|---|---|---|---|
| 8324ba8456 | |||
| 89a4140b53 |
@@ -154,9 +154,13 @@ public class UserContentController : ControllerBase
|
||||
/// [AUTHED] Delete an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Deletes an image, granted it exists. <br/>
|
||||
/// Deletes an image, granted it exists.
|
||||
/// <br/><br/>
|
||||
/// <b>Note</b>:
|
||||
/// If the image is a file on disk, it's also deleted.
|
||||
/// If the image is a file on disk, it's also deleted.
|
||||
/// <br/><br/>
|
||||
/// <b>Warning</b>:
|
||||
/// Any reference to deleted image in Quotes table will also be deleted (nullified).
|
||||
/// </remarks>
|
||||
/// <returns>Json with status</returns>
|
||||
/// <param name="id">Image id which will be deleted</param>
|
||||
@@ -189,6 +193,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