2 Commits

View File

@@ -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();