Exemple #1
0
        public int?CreateOrUpdateForums(long projectId, short[] bookTypeIds = null)
        {
            if (m_forumOptions.IsEnabled == false)
            {
                return(null);
            }

            var work    = new GetProjectWork(m_projectRepository, m_metadataRepository, projectId, true, true, false, true);
            var project = work.Execute();

            if (project == null)
            {
                throw new ForumException(MainServiceErrorCode.ProjectNotExist, "The project does not exist.");
            }

            var projectDetailContract = m_mapper.Map <ProjectDetailContract>(project);

            projectDetailContract.PageCount = work.GetPageCount();
            if (bookTypeIds == null && project.LatestPublishedSnapshot != null)
            {
                bookTypeIds = project.LatestPublishedSnapshot.BookTypes.Select(x => (short)x.Type).ToArray();
            }


            if (project.ForumId != null)
            {
                m_forumManager.UpdateForum(projectDetailContract, bookTypeIds);
            }

            var forum = m_forumManager.GetForumByExternalId(project.Id);

            if (forum == null)
            {
                //Create forum
                var forumId = m_forumManager.CreateNewForum(projectDetailContract, bookTypeIds);
                new SetForumIdToProjectWork(m_projectRepository, projectId, forumId).Execute();
                return(forumId);
            }

            //Forum is created, but not connect with project -> set ForumId to Project
            new SetForumIdToProjectWork(m_projectRepository, projectId, forum.ForumID).Execute();
            return(forum.ForumID);
        }