public Contract_AnimeSeries_SaveResponse SaveSeries(Contract_AnimeSeries_Save contract, int userID) { Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse(); contractout.ErrorMessage = ""; contractout.AnimeSeries = null; try { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = null; int? oldGroupID = null; if (contract.AnimeSeriesID.HasValue) { ser = repSeries.GetByID(contract.AnimeSeriesID.Value); if (ser == null) { contractout.ErrorMessage = "Could not find existing series with ID: " + contract.AnimeSeriesID.Value.ToString(); return contractout; } // check if we are moving a series oldGroupID = ser.AnimeGroupID; } else { ser = new AnimeSeries(); ser.DateTimeCreated = DateTime.Now; ser.DefaultAudioLanguage = ""; ser.DefaultSubtitleLanguage = ""; ser.MissingEpisodeCount = 0; ser.MissingEpisodeCountGroups = 0; ser.LatestLocalEpisodeNumber = 0; ser.SeriesNameOverride = ""; } ser.AnimeGroupID = contract.AnimeGroupID; ser.AniDB_ID = contract.AniDB_ID; ser.DefaultAudioLanguage = contract.DefaultAudioLanguage; ser.DefaultSubtitleLanguage = contract.DefaultSubtitleLanguage; ser.DateTimeUpdated = DateTime.Now; ser.SeriesNameOverride = contract.SeriesNameOverride; ser.DefaultFolder = contract.DefaultFolder; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(ser.AniDB_ID); if (anime == null) { contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID); return contractout; } repSeries.Save(ser); // update stats for groups //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true ,true, true); ser.QueueUpdateStats(); if (oldGroupID.HasValue) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeGroup grp = repGroups.GetByID(oldGroupID.Value); if (grp != null) { grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); } } List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2(); List<CrossRef_AniDB_MAL> xrefMAL = ser.CrossRefMAL; List<TvDB_Series> sers = new List<TvDB_Series>(); foreach (CrossRef_AniDB_TvDBV2 xref in xrefs) sers.Add(xref.GetTvDBSeries()); CrossRef_AniDB_Other xrefMovie = ser.CrossRefMovieDB; MovieDB_Movie movie = null; if (xrefMovie != null) movie = xrefMovie.GetMovieDB_Movie(); contractout.AnimeSeries = ser.ToContract(anime, xrefs, ser.CrossRefMovieDB, ser.GetUserRecord(userID), sers, xrefMAL, false, null, null, null, null,movie); return contractout; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); contractout.ErrorMessage = ex.Message; return contractout; } }
public Contract_AnimeSeries_SaveResponse MoveSeries(int animeSeriesID, int newAnimeGroupID, int userID) { Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse(); contractout.ErrorMessage = ""; contractout.AnimeSeries = null; try { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = null; ser = repSeries.GetByID(animeSeriesID); if (ser == null) { contractout.ErrorMessage = "Could not find existing series with ID: " + animeSeriesID.ToString(); return contractout; } // make sure the group exists AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeGroup grpTemp = repGroups.GetByID(newAnimeGroupID); if (grpTemp == null) { contractout.ErrorMessage = "Could not find existing group with ID: " + newAnimeGroupID.ToString(); return contractout; } int oldGroupID = ser.AnimeGroupID; ser.AnimeGroupID = newAnimeGroupID; ser.DateTimeUpdated = DateTime.Now; repSeries.Save(ser); // update stats for new groups //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); ser.QueueUpdateStats(); // update stats for old groups AnimeGroup grp = repGroups.GetByID(oldGroupID); if (grp != null) { grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); } AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(ser.AniDB_ID); if (anime == null) { contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID); return contractout; } List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2(); List<CrossRef_AniDB_MAL> xrefMAL = ser.CrossRefMAL; List<TvDB_Series> sers = new List<TvDB_Series>(); foreach (CrossRef_AniDB_TvDBV2 xref in xrefs) sers.Add(xref.GetTvDBSeries()); CrossRef_AniDB_Other xrefMovie = ser.CrossRefMovieDB; MovieDB_Movie movie=null; if (xrefMovie != null) movie = xrefMovie.GetMovieDB_Movie(); contractout.AnimeSeries = ser.ToContract(anime, xrefs, xrefMovie, ser.GetUserRecord(userID), sers, xrefMAL, false, null, null, null, null,movie); return contractout; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); contractout.ErrorMessage = ex.Message; return contractout; } }
public Contract_AnimeSeries_SaveResponse CreateSeriesFromAnime(int animeID, int? animeGroupID, int userID) { Contract_AnimeSeries_SaveResponse response = new Contract_AnimeSeries_SaveResponse(); response.AnimeSeries = null; response.ErrorMessage = ""; try { using (var session = JMMService.SessionFactory.OpenSession()) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); if (animeGroupID.HasValue) { AnimeGroup grp = repGroups.GetByID(session, animeGroupID.Value); if (grp == null) { response.ErrorMessage = "Could not find the specified group"; return response; } } // make sure a series doesn't already exists for this anime AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); if (ser != null) { response.ErrorMessage = "A series already exists for this anime"; return response; } // make sure the anime exists first AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, animeID); if (anime == null) anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, animeID, false, false); if (anime == null) { response.ErrorMessage = "Could not get anime information from AniDB"; return response; } if (animeGroupID.HasValue) { ser = new AnimeSeries(); ser.Populate(anime); ser.AnimeGroupID = animeGroupID.Value; repSeries.Save(ser); } else { ser = anime.CreateAnimeSeriesAndGroup(session); } ser.CreateAnimeEpisodes(session); // check if we have any group status data for this associated anime // if not we will download it now AniDB_GroupStatusRepository repStatus = new AniDB_GroupStatusRepository(); if (repStatus.GetByAnimeID(anime.AnimeID).Count == 0) { CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(anime.AnimeID, false); cmdStatus.Save(session); } ser.QueueUpdateStats(); // check for TvDB associations CommandRequest_TvDBSearchAnime cmd = new CommandRequest_TvDBSearchAnime(anime.AnimeID, false); cmd.Save(session); if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { // check for Trakt associations CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(anime.AnimeID, false); cmd2.Save(session); } List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2(); List<CrossRef_AniDB_MAL> xrefMAL = ser.CrossRefMAL; List<TvDB_Series> sers = new List<TvDB_Series>(); foreach (CrossRef_AniDB_TvDBV2 xref in xrefs) sers.Add(xref.GetTvDBSeries()); CrossRef_AniDB_Other xrefMovie = ser.CrossRefMovieDB; MovieDB_Movie movie = null; if (xrefMovie != null) movie = xrefMovie.GetMovieDB_Movie(); response.AnimeSeries = ser.ToContract(anime, xrefs, xrefMovie, ser.GetUserRecord(userID), sers, xrefMAL, false, null, null, null, null,movie); return response; } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); response.ErrorMessage = ex.Message; } return response; }
public Contract_AnimeSeries_SaveResponse SaveSeries(Contract_AnimeSeries_Save contract, int userID) { Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse(); contractout.ErrorMessage = ""; contractout.AnimeSeries = null; try { AnimeSeries ser = null; int? oldGroupID = null; if (contract.AnimeSeriesID.HasValue) { ser = RepoFactory.AnimeSeries.GetByID(contract.AnimeSeriesID.Value); if (ser == null) { contractout.ErrorMessage = "Could not find existing series with ID: " + contract.AnimeSeriesID.Value.ToString(); return contractout; } // check if we are moving a series oldGroupID = ser.AnimeGroupID; } else { ser = new AnimeSeries(); ser.DateTimeCreated = DateTime.Now; ser.DefaultAudioLanguage = ""; ser.DefaultSubtitleLanguage = ""; ser.MissingEpisodeCount = 0; ser.MissingEpisodeCountGroups = 0; ser.LatestLocalEpisodeNumber = 0; ser.SeriesNameOverride = ""; } ser.AnimeGroupID = contract.AnimeGroupID; ser.AniDB_ID = contract.AniDB_ID; ser.DefaultAudioLanguage = contract.DefaultAudioLanguage; ser.DefaultSubtitleLanguage = contract.DefaultSubtitleLanguage; ser.DateTimeUpdated = DateTime.Now; ser.SeriesNameOverride = contract.SeriesNameOverride; ser.DefaultFolder = contract.DefaultFolder; AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(ser.AniDB_ID); if (anime == null) { contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID); return contractout; } // update stats for groups //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true ,true, true); //Update and Save ser.UpdateStats(true, true, true); if (oldGroupID.HasValue) { AnimeGroup grp = RepoFactory.AnimeGroup.GetByID(oldGroupID.Value); if (grp != null) { grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); } } contractout.AnimeSeries = ser.GetUserContract(userID); return contractout; } catch (Exception ex) { logger.Error( ex,ex.ToString()); contractout.ErrorMessage = ex.Message; return contractout; } }
public Contract_AnimeSeries_SaveResponse MoveSeries(int animeSeriesID, int newAnimeGroupID, int userID) { Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse(); contractout.ErrorMessage = ""; contractout.AnimeSeries = null; try { AnimeSeries ser = null; ser = RepoFactory.AnimeSeries.GetByID(animeSeriesID); if (ser == null) { contractout.ErrorMessage = "Could not find existing series with ID: " + animeSeriesID.ToString(); return contractout; } // make sure the group exists AnimeGroup grpTemp = RepoFactory.AnimeGroup.GetByID(newAnimeGroupID); if (grpTemp == null) { contractout.ErrorMessage = "Could not find existing group with ID: " + newAnimeGroupID.ToString(); return contractout; } int oldGroupID = ser.AnimeGroupID; ser.AnimeGroupID = newAnimeGroupID; ser.DateTimeUpdated = DateTime.Now; // repSeries.Save(ser,false,false); // update stats for new groups //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); //Update and Save ser.UpdateStats(true, true, true); // update stats for old groups AnimeGroup grp = RepoFactory.AnimeGroup.GetByID(oldGroupID); if (grp != null) { AnimeGroup topGroup = grp.TopLevelAnimeGroup; if (grp.GetAllSeries().Count == 0) { RepoFactory.AnimeGroup.Delete(grp.AnimeGroupID); } if (topGroup.AnimeGroupID!=grp.AnimeGroupID) topGroup.UpdateStatsFromTopLevel(true, true, true); } AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(ser.AniDB_ID); if (anime == null) { contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID); return contractout; } contractout.AnimeSeries = ser.GetUserContract(userID); return contractout; } catch (Exception ex) { logger.Error( ex,ex.ToString()); contractout.ErrorMessage = ex.Message; return contractout; } }
public Contract_AnimeSeries_SaveResponse CreateSeriesFromAnime(int animeID, int? animeGroupID, int userID) { Contract_AnimeSeries_SaveResponse response = new Contract_AnimeSeries_SaveResponse(); response.AnimeSeries = null; response.ErrorMessage = ""; try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); if (animeGroupID.HasValue) { AnimeGroup grp = RepoFactory.AnimeGroup.GetByID(animeGroupID.Value); if (grp == null) { response.ErrorMessage = "Could not find the specified group"; return response; } } // make sure a series doesn't already exists for this anime AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(animeID); if (ser != null) { response.ErrorMessage = "A series already exists for this anime"; return response; } // make sure the anime exists first AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, animeID); if (anime == null) anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, animeID, false, false); if (anime == null) { response.ErrorMessage = "Could not get anime information from AniDB"; return response; } if (animeGroupID.HasValue) { ser = new AnimeSeries(); ser.Populate(anime); ser.AnimeGroupID = animeGroupID.Value; RepoFactory.AnimeSeries.Save(ser, false); } else { ser = anime.CreateAnimeSeriesAndGroup(sessionWrapper); } ser.CreateAnimeEpisodes(session); // check if we have any group status data for this associated anime // if not we will download it now if (RepoFactory.AniDB_GroupStatus.GetByAnimeID(anime.AnimeID).Count == 0) { CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(anime.AnimeID, false); cmdStatus.Save(session); } ser.UpdateStats(true, true, true); // check for TvDB associations CommandRequest_TvDBSearchAnime cmd = new CommandRequest_TvDBSearchAnime(anime.AnimeID, false); cmd.Save(session); if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { // check for Trakt associations CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(anime.AnimeID, false); cmd2.Save(session); } response.AnimeSeries = ser.GetUserContract(userID); return response; } } catch (Exception ex) { logger.Error( ex,ex.ToString()); response.ErrorMessage = ex.Message; } return response; }