示例#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);
                }
            }
        }
示例#2
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);
                }
            }

            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);
                StatsCache.Instance.UpdateUsingGroup(parentID);
            }
        }
示例#3
0
        public string DeleteUser(int userID)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                JMMUser jmmUser = repUsers.GetByID(userID);
                if (jmmUser == null) return "User not found";

                // make sure that at least one user is an admin
                if (jmmUser.IsAdmin == 1)
                {
                    bool adminExists = false;
                    List<JMMUser> users = repUsers.GetAll();
                    foreach (JMMUser userOld in users)
                    {
                        if (userOld.IsAdmin == 1)
                        {
                            if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true;
                        }
                    }

                    if (!adminExists) return "At least one user must be an administrator";
                }

                repUsers.Delete(userID);

                // delete all user records
                AnimeSeries_UserRepository repSeries = new AnimeSeries_UserRepository();
                foreach (AnimeSeries_User ser in repSeries.GetByUserID(userID))
                    repSeries.Delete(ser.AnimeSeries_UserID);

                AnimeGroup_UserRepository repGroup = new AnimeGroup_UserRepository();
                foreach (AnimeGroup_User grp in repGroup.GetByUserID(userID))
                    repGroup.Delete(grp.AnimeGroup_UserID);

                AnimeEpisode_UserRepository repEpisode = new AnimeEpisode_UserRepository();
                foreach (AnimeEpisode_User ep in repEpisode.GetByUserID(userID))
                    repEpisode.Delete(ep.AnimeEpisode_UserID);

                VideoLocal_UserRepository repVids = new VideoLocal_UserRepository();
                foreach (VideoLocal_User vid in repVids.GetByUserID(userID))
                    repVids.Delete(vid.VideoLocal_UserID);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }

            return "";
        }
示例#4
0
        public void RecreateAllGroups()
        {
            try
            {
                // pause queues
                JMMService.CmdProcessorGeneral.Paused = true;
                JMMService.CmdProcessorHasher.Paused = true;
                JMMService.CmdProcessorImages.Paused = true;

                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeGroup_UserRepository repGroupUser = new AnimeGroup_UserRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                // get all the old groups
                List<AnimeGroup> oldGroups = repGroups.GetAll();
                List<AnimeGroup_User> oldGroupUsers = repGroupUser.GetAll();

                // create a new group, where we will place all the series temporarily
                AnimeGroup tempGroup = new AnimeGroup();
                tempGroup.GroupName = "AAA Migrating Groups AAA";
                tempGroup.Description = "AAA Migrating Groups AAA";
                tempGroup.SortName = "AAA Migrating Groups AAA";
                tempGroup.DateTimeUpdated = DateTime.Now;
                tempGroup.DateTimeCreated = DateTime.Now;
                repGroups.Save(tempGroup);

                // move all series to the new group
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    ser.AnimeGroupID = tempGroup.AnimeGroupID;
                    repSeries.Save(ser, false);
                }

                // delete all the old groups
                foreach (AnimeGroup grp in oldGroups)
                    repGroups.Delete(grp.AnimeGroupID);

                // delete all the old group user records
                foreach (AnimeGroup_User grpUser in oldGroupUsers)
                    repGroupUser.Delete(grpUser.AnimeGroupID);

                // recreate groups
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    bool createNewGroup = true;

                    if (ServerSettings.AutoGroupSeries)
                    {
                        List<AnimeGroup> grps = AnimeGroup.GetRelatedGroupsFromAnimeID(ser.AniDB_ID);

                        // only use if there is just one result
                        if (grps != null && grps.Count > 0 && !grps[0].GroupName.Equals("AAA Migrating Groups AAA"))
                        {
                            ser.AnimeGroupID = grps[0].AnimeGroupID;
                            createNewGroup = false;
                        }
                    }

                    if (createNewGroup)
                    {
                        AnimeGroup anGroup = new AnimeGroup();
                        anGroup.Populate(ser);
                        repGroups.Save(anGroup);

                        ser.AnimeGroupID = anGroup.AnimeGroupID;
                    }

                    repSeries.Save(ser, false);
                }

                // delete the temp group
                if (tempGroup.GetAllSeries().Count == 0)
                    repGroups.Delete(tempGroup.AnimeGroupID);

                // create group user records and update group stats
                foreach (AnimeGroup grp in repGroups.GetAll())
                    grp.UpdateStatsFromTopLevel(true, true);

                // un-pause queues
                JMMService.CmdProcessorGeneral.Paused = false;
                JMMService.CmdProcessorHasher.Paused = false;
                JMMService.CmdProcessorImages.Paused = false;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
示例#5
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);
			}

			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);
				StatsCache.Instance.UpdateUsingGroup(parentID);
			}
		}