Пример #1
0
        protected override void ExecuteWorkImplementation()
        {
            foreach (var bookType in BookTypeHelper.GetBookTypeEnumsWithCategories())
            {
                var category = m_categoryRepository.GetCategoryByExternalId((short)bookType);
                var forum    = m_forumRepository.GetForumByExternalCategoryIdAndCategory(m_categoryId, category.CategoryID);

                if (forum == null)
                {
                    throw new MainServiceException(MainServiceErrorCode.EntityNotFound, "The entity was not found", HttpStatusCode.NotFound);
                }

                if (forum.Forums.Count > 0)
                {
                    throw new MainServiceException(MainServiceErrorCode.CategoryHasSubCategories, "Category has some sub-categories", HttpStatusCode.BadRequest);
                }

                var forumAccesses = m_forumRepository.GetAllAccessesForForum(forum.ForumID);
                m_forumRepository.DeleteAll(forumAccesses);
                m_forumRepository.Delete(forum);
            }
        }
        protected override void ExecuteWorkImplementation()
        {
            IList <int> newCategories     = m_categoryIds.Except(m_oldCategoryIds).ToList();
            IList <int> deletedCategories = m_oldCategoryIds.Except(m_categoryIds).ToList();

            var mainForum = m_forumRepository.GetMainForumByExternalProjectId(m_projectId);

            if (mainForum == null)
            {
                return;
            }

            var forumCategoriesToDelete = m_forumRepository.GetForumsByExternalCategoryIds(deletedCategories);
            var forums = m_forumRepository.GetForumsByExternalProjectId(m_projectId);

            foreach (var forum in forums)
            {
                if (forumCategoriesToDelete.Contains(forum.ParentForum))
                {
                    var forumAccesses = m_forumRepository.GetAllAccessesForForum(forum.ForumID);
                    m_forumRepository.DeleteAll(forumAccesses);
                    m_forumRepository.Delete(forum);
                }
            }

            var forumsToCreate = m_forumRepository.GetForumsByExternalCategoryIds(newCategories);

            foreach (var forum in forumsToCreate)
            {
                var tempForum = new Forum(mainForum.Name, forum.Category, (short)ForumTypeEnum.Forum)
                {
                    ExternalProjectId = m_projectId,
                    ParentForum       = forum,
                    RemoteURL         = m_forumSiteUrlHelper.GetTopicsUrl(mainForum.ForumID)
                };
                m_forumRepository.Create(tempForum);
                m_forumAccessSubwork.SetAdminAccessToForumForAdminGroup(tempForum);
            }
        }