Example #1
0
        public void Delete(int id)
        {
            AnimeGroup cr = GetByID(id);

            if (cr != null)
            {
                // delete user records
                AnimeGroup_UserRepository repUsers = new AnimeGroup_UserRepository();
                foreach (AnimeGroup_User grpUser in repUsers.GetByGroupID(id))
                {
                    repUsers.Delete(grpUser.AnimeGroup_UserID);
                }
                cr.DeleteFromFilters();
                Cache.Remove(cr);
                Changes.Remove(cr.AnimeGroupID);
            }

            int parentID = 0;

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                // populate the database
                using (var transaction = session.BeginTransaction())
                {
                    if (cr != null)
                    {
                        if (cr.AnimeGroupParentID.HasValue)
                        {
                            parentID = cr.AnimeGroupParentID.Value;
                        }
                        session.Delete(cr);
                        transaction.Commit();
                    }
                }
            }

            if (parentID > 0)
            {
                logger.Trace("Updating group stats by group from AnimeGroupRepository.Delete: {0}", parentID);
                AnimeGroup ngrp = GetByID(parentID);
                if (ngrp != null)
                {
                    this.Save(ngrp, false, true);
                }
            }
        }