mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-17 07:10:05 +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
|
/// [AUTHED] Delete an image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Deletes an image, granted it exists. <br/>
|
/// Deletes an image, granted it exists.
|
||||||
|
/// <br/><br/>
|
||||||
/// <b>Note</b>:
|
/// <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>
|
/// </remarks>
|
||||||
/// <returns>Json with status</returns>
|
/// <returns>Json with status</returns>
|
||||||
/// <param name="id">Image id which will be deleted</param>
|
/// <param name="id">Image id which will be deleted</param>
|
||||||
@@ -189,6 +193,18 @@ public class UserContentController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// - from db
|
// - 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);
|
_db.Images.Remove(image);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user