public static string DeleteImportFolder(int importFolderID) { try { ImportFolderRepository repNS = new ImportFolderRepository(); ImportFolder ns = repNS.GetByID(importFolderID); if (ns == null) return "Could not find Import Folder ID: " + importFolderID; // first delete all the files attached to this import folder Dictionary<int, AnimeSeries> affectedSeries = new Dictionary<int, AnimeSeries>(); VideoLocalRepository repVids = new VideoLocalRepository(); foreach (VideoLocal vid in repVids.GetByImportFolder(importFolderID)) { //Thread.Sleep(5000); logger.Info("Deleting video local record: {0}", vid.FullServerPath); AnimeSeries ser = null; List<AnimeEpisode> animeEpisodes = vid.GetAnimeEpisodes(); if (animeEpisodes.Count > 0) { ser = animeEpisodes[0].GetAnimeSeries(); if (ser != null && !affectedSeries.ContainsKey(ser.AnimeSeriesID)) affectedSeries.Add(ser.AnimeSeriesID, ser); } repVids.Delete(vid.VideoLocalID); } // delete any duplicate file records which reference this folder DuplicateFileRepository repDupFiles = new DuplicateFileRepository(); foreach (DuplicateFile df in repDupFiles.GetByImportFolder1(importFolderID)) repDupFiles.Delete(df.DuplicateFileID); foreach (DuplicateFile df in repDupFiles.GetByImportFolder2(importFolderID)) repDupFiles.Delete(df.DuplicateFileID); // delete the import folder repNS.Delete(importFolderID); ServerInfo.Instance.RefreshImportFolders(); foreach (AnimeSeries ser in affectedSeries.Values) { ser.QueueUpdateStats(); //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); } return ""; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } }