public void Save(AniDB_Anime_Tag obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
private void CreateTags(ISession session, List<Raw_AniDB_Tag> tags) { if (tags == null) return; this.AllTags = ""; AniDB_TagRepository repTags = new AniDB_TagRepository(); AniDB_Anime_TagRepository repTagsXRefs = new AniDB_Anime_TagRepository(); List<AniDB_Tag> tagsToSave = new List<AniDB_Tag>(); List<AniDB_Anime_Tag> xrefsToSave = new List<AniDB_Anime_Tag>(); List<AniDB_Anime_Tag> xrefsToDelete = new List<AniDB_Anime_Tag>(); // find all the current links, and then later remove the ones that are no longer relevant List<AniDB_Anime_Tag> currentTags = repTagsXRefs.GetByAnimeID(AnimeID); List<int> newTagIDs = new List<int>(); foreach (Raw_AniDB_Tag rawtag in tags) { AniDB_Tag tag = repTags.GetByTagID(rawtag.TagID, session); if (tag == null) tag = new AniDB_Tag(); tag.Populate(rawtag); tagsToSave.Add(tag); newTagIDs.Add(tag.TagID); AniDB_Anime_Tag anime_tag = repTagsXRefs.GetByAnimeIDAndTagID(session, rawtag.AnimeID, rawtag.TagID); if (anime_tag == null) anime_tag = new AniDB_Anime_Tag(); anime_tag.Populate(rawtag); xrefsToSave.Add(anime_tag); if (this.AllTags.Length > 0) this.AllTags += "|"; this.AllTags += tag.TagName; } foreach (AniDB_Anime_Tag curTag in currentTags) { if (!newTagIDs.Contains(curTag.TagID)) xrefsToDelete.Add(curTag); } using (var transaction = session.BeginTransaction()) { foreach (AniDB_Tag tag in tagsToSave) session.SaveOrUpdate(tag); foreach (AniDB_Anime_Tag xref in xrefsToSave) session.SaveOrUpdate(xref); foreach (AniDB_Anime_Tag xref in xrefsToDelete) repTagsXRefs.Delete(xref.AniDB_Anime_TagID); transaction.Commit(); } }
private void CreateTags(ISession session, List<Raw_AniDB_Tag> tags) { if (tags == null) return; this.AllTags = ""; AniDB_TagRepository repTags = new AniDB_TagRepository(); AniDB_Anime_TagRepository repTagsXRefs = new AniDB_Anime_TagRepository(); List<AniDB_Tag> tagsToSave = new List<AniDB_Tag>(); List<AniDB_Anime_Tag> xrefsToSave = new List<AniDB_Anime_Tag>(); foreach (Raw_AniDB_Tag rawtag in tags) { AniDB_Tag tag = repTags.GetByTagID(rawtag.TagID, session); if (tag == null) tag = new AniDB_Tag(); tag.Populate(rawtag); tagsToSave.Add(tag); AniDB_Anime_Tag anime_tag = repTagsXRefs.GetByAnimeIDAndTagID(session, rawtag.AnimeID, rawtag.TagID); if (anime_tag == null) anime_tag = new AniDB_Anime_Tag(); anime_tag.Populate(rawtag); xrefsToSave.Add(anime_tag); if (this.AllTags.Length > 0) this.AllTags += "|"; this.AllTags += tag.TagName; } using (var transaction = session.BeginTransaction()) { foreach (AniDB_Tag tag in tagsToSave) session.SaveOrUpdate(tag); foreach (AniDB_Anime_Tag xref in xrefsToSave) session.SaveOrUpdate(xref); transaction.Commit(); } }
private void CreateTags(List<Raw_AniDB_Tag> tags) { if (tags == null) return; this.AllTags = ""; List<AniDB_Tag> tagsToSave = new List<AniDB_Tag>(); List<AniDB_Anime_Tag> xrefsToSave = new List<AniDB_Anime_Tag>(); List<AniDB_Anime_Tag> xrefsToDelete = new List<AniDB_Anime_Tag>(); // find all the current links, and then later remove the ones that are no longer relevant List<AniDB_Anime_Tag> currentTags = RepoFactory.AniDB_Anime_Tag.GetByAnimeID(AnimeID); List<int> newTagIDs = new List<int>(); foreach (Raw_AniDB_Tag rawtag in tags) { AniDB_Tag tag = RepoFactory.AniDB_Tag.GetByTagID(rawtag.TagID); if (tag == null) tag = new AniDB_Tag(); tag.Populate(rawtag); tagsToSave.Add(tag); newTagIDs.Add(tag.TagID); AniDB_Anime_Tag anime_tag = RepoFactory.AniDB_Anime_Tag.GetByAnimeIDAndTagID(rawtag.AnimeID, rawtag.TagID); if (anime_tag == null) anime_tag = new AniDB_Anime_Tag(); anime_tag.Populate(rawtag); xrefsToSave.Add(anime_tag); if (this.AllTags.Length > 0) this.AllTags += "|"; this.AllTags += tag.TagName; } foreach (AniDB_Anime_Tag curTag in currentTags) { if (!newTagIDs.Contains(curTag.TagID)) xrefsToDelete.Add(curTag); } RepoFactory.AniDB_Tag.Save(tagsToSave); RepoFactory.AniDB_Anime_Tag.Save(xrefsToSave); RepoFactory.AniDB_Anime_Tag.Delete(xrefsToDelete); }