public async Task <IActionResult> DeleteConfirmed(int id) { Song songFromDb = await _mediaWebDbContext.Songs.FirstOrDefaultAsync(s => s.Id == id); if (!string.IsNullOrEmpty(songFromDb.SongFile)) { _uploadUtility.DeleteFile(_hostingEnvironment.WebRootPath, songFromDb.SongFile); } _mediaWebDbContext.Songs.Remove(songFromDb); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteConfirmed(int id) { TVshow tvshowFromDB = await _mediaWebDbContext.TVShows.FirstOrDefaultAsync(m => m.Id == id); if (!string.IsNullOrEmpty(tvshowFromDB.Picture)) { _uploadUtility.DeleteFile(_hostingEnvironment.WebRootPath, tvshowFromDB.Picture); } _mediaWebDbContext.TVShows.Remove(tvshowFromDB); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteConfirmed(int id) { Movie movieFromDb = await _mediaWebDbContext.Movies.FirstOrDefaultAsync(m => m.Id == id); //delete file aswell if (!string.IsNullOrEmpty(movieFromDb.Photo)) { _uploadUtility.DeleteFile(_hostingEnvironment.WebRootPath, movieFromDb.Photo); } _mediaWebDbContext.Movies.Remove(movieFromDb); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }