public string RemoveAssociationOnFile(int videoLocalID, int aniDBEpisodeID) { try { VideoLocalRepository repVids = new VideoLocalRepository(); CrossRef_File_EpisodeRepository repXRefs = new CrossRef_File_EpisodeRepository(); VideoLocal vid = repVids.GetByID(videoLocalID); if (vid == null) return "Could not find video record"; int? animeSeriesID = null; foreach (AnimeEpisode ep in vid.GetAnimeEpisodes()) { if (ep.AniDB_EpisodeID != aniDBEpisodeID) continue; animeSeriesID = ep.AnimeSeriesID; CrossRef_File_Episode xref = repXRefs.GetByHashAndEpisodeID(vid.Hash, ep.AniDB_EpisodeID); if (xref != null) { if (xref.CrossRefSource == (int)CrossRefSource.AniDB) return "Cannot remove associations created from AniDB data"; // delete cross ref from web cache CommandRequest_WebCacheDeleteXRefFileEpisode cr = new CommandRequest_WebCacheDeleteXRefFileEpisode(vid.Hash, ep.AniDB_EpisodeID); cr.Save(); repXRefs.Delete(xref.CrossRef_File_EpisodeID); } } if (animeSeriesID.HasValue) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = repSeries.GetByID(animeSeriesID.Value); if (ser != null) ser.QueueUpdateStats(); } return ""; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } }
public void CreateCrossEpisodes(string localFileName) { if (episodesRAW != null) //Only create relations if the origin of the data if from Raw (AniDB) { CrossRef_File_EpisodeRepository repFileEpisodes = new CrossRef_File_EpisodeRepository(); List<CrossRef_File_Episode> fileEps = repFileEpisodes.GetByHash(this.Hash); foreach (CrossRef_File_Episode fileEp in fileEps) repFileEpisodes.Delete(fileEp.CrossRef_File_EpisodeID); char apostrophe = ("'").ToCharArray()[0]; char epiSplit = ','; if (episodesRAW.Contains(apostrophe)) epiSplit = apostrophe; char eppSplit = ','; if (episodesPercentRAW.Contains(apostrophe)) eppSplit = apostrophe; string[] epi = episodesRAW.Split(epiSplit); string[] epp = episodesPercentRAW.Split(eppSplit); for (int x = 0; x < epi.Length; x++) { string epis = epi[x].Trim(); string epps = epp[x].Trim(); if (epis.Length > 0) { int epid = 0; int.TryParse(epis, out epid); int eppp = 100; int.TryParse(epps, out eppp); if (epid != 0) { CrossRef_File_Episode cross = new CrossRef_File_Episode(); cross.Hash = Hash; cross.CrossRefSource = (int)CrossRefSource.AniDB; cross.AnimeID = this.AnimeID; cross.EpisodeID = epid; cross.Percentage = eppp; cross.EpisodeOrder = x + 1; cross.FileName = localFileName; cross.FileSize = FileSize; repFileEpisodes.Save(cross); } } } } }