public void Save(AniDB_Anime_DefaultImage obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
Ejemplo n.º 2
0
        public string SetDefaultImage(bool isDefault, int animeID, int imageID, int imageType, int imageSizeType)
        {
            try
            {
                AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();

                JMMImageType imgType = (JMMImageType)imageType;
                ImageSizeType sizeType = ImageSizeType.Poster;

                switch (imgType)
                {
                    case JMMImageType.AniDB_Cover:
                    case JMMImageType.TvDB_Cover:
                    case JMMImageType.MovieDB_Poster:
                    case JMMImageType.Trakt_Poster:
                        sizeType = ImageSizeType.Poster;
                        break;

                    case JMMImageType.TvDB_Banner:
                        sizeType = ImageSizeType.WideBanner;
                        break;

                    case JMMImageType.TvDB_FanArt:
                    case JMMImageType.MovieDB_FanArt:
                    case JMMImageType.Trakt_Fanart:
                        sizeType = ImageSizeType.Fanart;
                        break;
                }

                if (!isDefault)
                {
                    // this mean we are removing an image as deafult
                    // which esssential means deleting the record

                    AniDB_Anime_DefaultImage img = repDefaults.GetByAnimeIDAndImagezSizeType(animeID, (int)sizeType);
                    if (img != null)
                        repDefaults.Delete(img.AniDB_Anime_DefaultImageID);
                }
                else
                {
                    // making the image the default for it's type (poster, fanart etc)
                    AniDB_Anime_DefaultImage img = repDefaults.GetByAnimeIDAndImagezSizeType(animeID, (int)sizeType);
                    if (img == null)
                        img = new AniDB_Anime_DefaultImage();

                    img.AnimeID = animeID;
                    img.ImageParentID = imageID;
                    img.ImageParentType = (int)imgType;
                    img.ImageType = (int)sizeType;
                    repDefaults.Save(img);
                }

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Ejemplo n.º 3
0
        public Contract_AnimeSeries ToContract(AniDB_Anime animeRec, List <CrossRef_AniDB_TvDBV2> tvDBCrossRefs, CrossRef_AniDB_Other movieDBCrossRef,
                                               AnimeSeries_User userRecord, List <TvDB_Series> tvseries, List <CrossRef_AniDB_MAL> malDBCrossRef, bool passedDefaultImages, AniDB_Anime_DefaultImage defPoster,
                                               AniDB_Anime_DefaultImage defFanart, AniDB_Anime_DefaultImage defWideBanner, List <AniDB_Anime_Title> titles, bool forceimages = false)
        {
            Contract_AnimeSeries contract = new Contract_AnimeSeries();

            contract.AniDB_ID                  = this.AniDB_ID;
            contract.AnimeGroupID              = this.AnimeGroupID;
            contract.AnimeSeriesID             = this.AnimeSeriesID;
            contract.DateTimeUpdated           = this.DateTimeUpdated;
            contract.DateTimeCreated           = this.DateTimeCreated;
            contract.DefaultAudioLanguage      = this.DefaultAudioLanguage;
            contract.DefaultSubtitleLanguage   = this.DefaultSubtitleLanguage;
            contract.LatestLocalEpisodeNumber  = this.LatestLocalEpisodeNumber;
            contract.EpisodeAddedDate          = this.EpisodeAddedDate;
            contract.MissingEpisodeCount       = this.MissingEpisodeCount;
            contract.MissingEpisodeCountGroups = this.MissingEpisodeCountGroups;
            contract.SeriesNameOverride        = this.SeriesNameOverride;



            if (userRecord == null)
            {
                contract.PlayedCount           = 0;
                contract.StoppedCount          = 0;
                contract.UnwatchedEpisodeCount = 0;
                contract.WatchedCount          = 0;
                contract.WatchedDate           = null;
                contract.WatchedEpisodeCount   = 0;
            }
            else
            {
                contract.PlayedCount           = userRecord.PlayedCount;
                contract.StoppedCount          = userRecord.StoppedCount;
                contract.UnwatchedEpisodeCount = userRecord.UnwatchedEpisodeCount;
                contract.WatchedCount          = userRecord.WatchedCount;
                contract.WatchedDate           = userRecord.WatchedDate;
                contract.WatchedEpisodeCount   = userRecord.WatchedEpisodeCount;
            }

            // get AniDB data
            contract.AniDBAnime = null;
            if (animeRec != null)
            {
                Contract_AniDBAnime animecontract = animeRec.ToContract(false, titles);

                AniDB_Anime_DefaultImage defaultPoster = null;
                if (passedDefaultImages)
                {
                    defaultPoster = defPoster;
                }
                else
                {
                    defaultPoster = animeRec.GetDefaultPoster();
                }

                if (defaultPoster == null)
                {
                    animecontract.DefaultImagePoster = null;
                }
                else
                {
                    animecontract.DefaultImagePoster = defaultPoster.ToContract();
                }

                if ((animecontract.DefaultImagePoster == null) && (forceimages))
                {
                    ImageDetails im = animeRec.GetDefaultPosterDetailsNoBlanks();
                    if (im != null)
                    {
                        animecontract.DefaultImagePoster           = new Contract_AniDB_Anime_DefaultImage();
                        animecontract.DefaultImagePoster.AnimeID   = im.ImageID;
                        animecontract.DefaultImagePoster.ImageType = (int)im.ImageType;
                    }
                }
                AniDB_Anime_DefaultImage defaultFanart = null;
                if (passedDefaultImages)
                {
                    defaultFanart = defFanart;
                }
                else
                {
                    defaultFanart = animeRec.GetDefaultFanart();
                }

                if (defaultFanart == null)
                {
                    animecontract.DefaultImageFanart = null;
                }
                else
                {
                    animecontract.DefaultImageFanart = defaultFanart.ToContract();
                }

                if ((animecontract.DefaultImagePoster == null) && (forceimages))
                {
                    ImageDetails im = animeRec.GetDefaultFanartDetailsNoBlanks();
                    if (im != null)
                    {
                        animecontract.DefaultImageFanart           = new Contract_AniDB_Anime_DefaultImage();
                        animecontract.DefaultImageFanart.AnimeID   = im.ImageID;
                        animecontract.DefaultImageFanart.ImageType = (int)im.ImageType;
                    }
                }

                AniDB_Anime_DefaultImage defaultWideBanner = null;
                if (passedDefaultImages)
                {
                    defaultWideBanner = defWideBanner;
                }
                else
                {
                    defaultWideBanner = animeRec.GetDefaultWideBanner();
                }

                if (defaultWideBanner == null)
                {
                    animecontract.DefaultImageWideBanner = null;
                }
                else
                {
                    animecontract.DefaultImageWideBanner = defaultWideBanner.ToContract();
                }

                contract.AniDBAnime = animecontract;
            }

            contract.CrossRefAniDBTvDBV2 = new List <Contract_CrossRef_AniDB_TvDBV2>();
            foreach (CrossRef_AniDB_TvDBV2 tvXref in tvDBCrossRefs)
            {
                contract.CrossRefAniDBTvDBV2.Add(tvXref.ToContract());
            }


            contract.TvDB_Series = new List <Contract_TvDB_Series>();
            foreach (TvDB_Series ser in tvseries)
            {
                contract.TvDB_Series.Add(ser.ToContract());
            }

            contract.CrossRefAniDBMovieDB = null;
            if (movieDBCrossRef != null)
            {
                contract.CrossRefAniDBMovieDB = movieDBCrossRef.ToContract();
            }

            contract.CrossRefAniDBMAL = new List <Contract_CrossRef_AniDB_MAL>();
            if (malDBCrossRef != null)
            {
                foreach (CrossRef_AniDB_MAL xref in malDBCrossRef)
                {
                    contract.CrossRefAniDBMAL.Add(xref.ToContract());
                }
            }

            return(contract);
        }