public void Save(CrossRef_Subtitles_AniDB_File obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
Example #2
0
		public void CreateLanguages()
		{
			char apostrophe = ("'").ToCharArray()[0];

			LanguageRepository repLanguages = new LanguageRepository();

			if (languagesRAW != null) //Only create relations if the origin of the data if from Raw (WebService/AniDB)
			{
				if (languagesRAW.Trim().Length == 0) return;
				// Delete old if changed

				CrossRef_Languages_AniDB_FileRepository repFileLanguages = new CrossRef_Languages_AniDB_FileRepository();
				

				List<CrossRef_Languages_AniDB_File> fileLanguages = repFileLanguages.GetByFileID(this.FileID);
				foreach (CrossRef_Languages_AniDB_File fLan in fileLanguages)
				{
					repFileLanguages.Delete(fLan.CrossRef_Languages_AniDB_FileID);
				}
	

				string[] langs = languagesRAW.Split(apostrophe);
				foreach (string language in langs)
				{
					string rlan = language.Trim().ToLower();
					if (rlan.Length > 0)
					{
						Language lan = repLanguages.GetByLanguageName(rlan);
						if (lan == null)
						{
							lan = new Language();
							lan.LanguageName = rlan;
							repLanguages.Save(lan);
						}
						CrossRef_Languages_AniDB_File cross = new CrossRef_Languages_AniDB_File();
						cross.LanguageID = lan.LanguageID;
						cross.FileID = FileID;
						repFileLanguages.Save(cross);
					}
				}
			}

			if (subtitlesRAW != null)
			{
				if (subtitlesRAW.Trim().Length == 0) return;

				// Delete old if changed
				CrossRef_Subtitles_AniDB_FileRepository repFileSubtitles = new CrossRef_Subtitles_AniDB_FileRepository();
				List<CrossRef_Subtitles_AniDB_File> fileSubtitles = repFileSubtitles.GetByFileID(this.FileID);

				foreach (CrossRef_Subtitles_AniDB_File fSub in fileSubtitles)
				{
					repFileSubtitles.Delete(fSub.CrossRef_Subtitles_AniDB_FileID);
				}

				string[] subs = subtitlesRAW.Split(apostrophe);
				foreach (string language in subs)
				{
					string rlan = language.Trim().ToLower();
					if (rlan.Length > 0)
					{
						Language lan = repLanguages.GetByLanguageName(rlan);
						if (lan == null)
						{
							lan = new Language();
							lan.LanguageName = rlan;
							repLanguages.Save(lan);
						}
						CrossRef_Subtitles_AniDB_File cross = new CrossRef_Subtitles_AniDB_File();
						cross.LanguageID = lan.LanguageID;
						cross.FileID = FileID;
						repFileSubtitles.Save(cross);
					}
				}
			}
		}
Example #3
0
        public void CreateLanguages()
        {
            char apostrophe = "'".ToCharArray()[0];

            LanguageRepository repLanguages = new LanguageRepository();

            if (languagesRAW != null) //Only create relations if the origin of the data if from Raw (WebService/AniDB)
            {
                if (languagesRAW.Trim().Length == 0)
                {
                    return;
                }
                // Delete old if changed

                CrossRef_Languages_AniDB_FileRepository repFileLanguages = new CrossRef_Languages_AniDB_FileRepository();


                List <CrossRef_Languages_AniDB_File> fileLanguages = repFileLanguages.GetByFileID(this.FileID);
                foreach (CrossRef_Languages_AniDB_File fLan in fileLanguages)
                {
                    repFileLanguages.Delete(fLan.CrossRef_Languages_AniDB_FileID);
                }


                string[] langs = languagesRAW.Split(apostrophe);
                foreach (string language in langs)
                {
                    string rlan = language.Trim().ToLower();
                    if (rlan.Length > 0)
                    {
                        Language lan = repLanguages.GetByLanguageName(rlan);
                        if (lan == null)
                        {
                            lan = new Language();
                            lan.LanguageName = rlan;
                            repLanguages.Save(lan);
                        }
                        CrossRef_Languages_AniDB_File cross = new CrossRef_Languages_AniDB_File();
                        cross.LanguageID = lan.LanguageID;
                        cross.FileID     = FileID;
                        repFileLanguages.Save(cross);
                    }
                }
            }

            if (subtitlesRAW != null)
            {
                if (subtitlesRAW.Trim().Length == 0)
                {
                    return;
                }

                // Delete old if changed
                CrossRef_Subtitles_AniDB_FileRepository repFileSubtitles = new CrossRef_Subtitles_AniDB_FileRepository();
                List <CrossRef_Subtitles_AniDB_File>    fileSubtitles    = repFileSubtitles.GetByFileID(this.FileID);

                foreach (CrossRef_Subtitles_AniDB_File fSub in fileSubtitles)
                {
                    repFileSubtitles.Delete(fSub.CrossRef_Subtitles_AniDB_FileID);
                }

                string[] subs = subtitlesRAW.Split(apostrophe);
                foreach (string language in subs)
                {
                    string rlan = language.Trim().ToLower();
                    if (rlan.Length > 0)
                    {
                        Language lan = repLanguages.GetByLanguageName(rlan);
                        if (lan == null)
                        {
                            lan = new Language();
                            lan.LanguageName = rlan;
                            repLanguages.Save(lan);
                        }
                        CrossRef_Subtitles_AniDB_File cross = new CrossRef_Subtitles_AniDB_File();
                        cross.LanguageID = lan.LanguageID;
                        cross.FileID     = FileID;
                        repFileSubtitles.Save(cross);
                    }
                }
            }
        }