public void Save(AniDB_Anime_Category obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
Exemplo n.º 2
0
		private void CreateCategories(ISession session, List<Raw_AniDB_Category> cats)
		{
			if (cats == null) return;

			this.AllCategories = "";

			AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
			AniDB_Anime_CategoryRepository repXRefs = new AniDB_Anime_CategoryRepository();

			int count = 0;

			List<AniDB_Category> catsToSave = new List<AniDB_Category>();
			List<AniDB_Anime_Category> xrefsToSave = new List<AniDB_Anime_Category>();

			foreach (Raw_AniDB_Category rawcat in cats)
			{
				count++;

				AniDB_Category cat = session
				.CreateCriteria(typeof(AniDB_Category))
				.Add(Restrictions.Eq("CategoryID", rawcat.CategoryID))
				.UniqueResult<AniDB_Category>();

				if (cat == null) cat = new AniDB_Category();

				cat.Populate(rawcat);
				catsToSave.Add(cat);

				AniDB_Anime_Category anime_cat = session
					.CreateCriteria(typeof(AniDB_Anime_Category))
					.Add(Restrictions.Eq("AnimeID", rawcat.AnimeID))
					.Add(Restrictions.Eq("CategoryID", rawcat.CategoryID))
					.UniqueResult<AniDB_Anime_Category>();

				if (anime_cat == null) anime_cat = new AniDB_Anime_Category();

				anime_cat.Populate(rawcat);
				xrefsToSave.Add(anime_cat);

				if (this.AllCategories.Length > 0) this.AllCategories += "|";
				this.AllCategories += cat.CategoryName;
			}

			using (var transaction = session.BeginTransaction())
			{
				foreach (AniDB_Category cat in catsToSave)
					session.SaveOrUpdate(cat);

				foreach (AniDB_Anime_Category xref in xrefsToSave)
					session.SaveOrUpdate(xref);

				transaction.Commit();
			}
		}