From 785892decb7864c2d23d0a937ee88228433b55a8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 29 May 2019 00:39:39 +0100 Subject: [PATCH] Remove files when machine photo is removed. --- .../Areas/Admin/Controllers/MachinePhotosController.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs b/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs index 593607e4..8197e15d 100644 --- a/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs +++ b/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs @@ -452,6 +452,14 @@ namespace cicm_web.Areas.Admin.Controllers MachinePhoto machinePhoto = await _context.MachinePhotos.FindAsync(id); _context.MachinePhotos.Remove(machinePhoto); await _context.SaveChangesAsync(); + + foreach(string format in new[] {"jpg", "webp"}) + { + foreach(int multiplier in new[] {1, 2, 3}) + System.IO.File.Delete(Path.Combine(hostingEnvironment.WebRootPath, "assets/photos/machines/thumbs", + format, $"{multiplier}x", id + $".{format}")); + } + return RedirectToAction(nameof(Index)); }