public void Save(AnimeGroup grp, bool updategrpcontractstats, bool recursive, bool verifylockedFilters = true) { using (var session = JMMService.SessionFactory.OpenSession()) { HashSet <GroupFilterConditionType> types; lock (grp) { if (grp.AnimeGroupID == 0) //We are creating one, and we need the AnimeGroupID before Update the contracts { grp.Contract = null; using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(grp); transaction.Commit(); } } types = grp.UpdateContract(session, updategrpcontractstats); //Types will contains the affected GroupFilterConditionTypes using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(grp); transaction.Commit(); } Changes.AddOrUpdate(grp.AnimeGroupID); Cache.Update(grp); } if (verifylockedFilters) { GroupFilterRepository.CreateOrVerifyTagsAndYearsFilters(false, grp.Contract.Stat_AllTags, grp.Contract.Stat_AirDate_Min); //This call will create extra years or tags if the Group have a new year or tag grp.UpdateGroupFilters(types, null); } if (grp.AnimeGroupParentID.HasValue && recursive) { AnimeGroup pgroup = GetByID(session, grp.AnimeGroupParentID.Value); // This will avoid the recursive error that would be possible, it won't update it, but that would be // the least of the issues if (pgroup != null && pgroup.AnimeGroupParentID == grp.AnimeGroupID) { Save(pgroup, updategrpcontractstats, true, verifylockedFilters); } } } }