예제 #1
0
        protected BooksAndCategoriesContract GetBooksAndCategories(bool fetchBooks = false)
        {
            var categoryClient = GetCodeListClient();
            var categories     = categoryClient.GetCategoryList();

            // Modify data for DropDownSelect usage

            const int rootCategoryId       = 0;
            var       rootBookTypeCategory = new CategoryContract
            {
                Id               = rootCategoryId,
                Description      = BookTypeHelper.GetCategoryName(AreaBookType),
                ParentCategoryId = null,
            };

            foreach (var category in categories)
            {
                if (category.ParentCategoryId == null)
                {
                    category.ParentCategoryId = rootCategoryId;
                }
            }

            categories.Add(rootBookTypeCategory);

            var booksResult = new List <BookWithCategoryIdsContract>();

            if (fetchBooks)
            {
                var bookClient = GetBookClient();
                var books      = bookClient.GetBooksByType(AreaBookType, 0, FetchBookCount);

                foreach (var book in books)
                {
                    var categoryIds = book.CategoryIds;
                    if (categoryIds.Count == 0)
                    {
                        categoryIds.Add(rootCategoryId);
                    }

                    booksResult.Add(new BookWithCategoryIdsContract
                    {
                        Id          = book.Id,
                        Title       = book.Title,
                        SubTitle    = book.SubTitle,
                        Guid        = null,
                        CategoryIds = categoryIds
                    });
                }
            }

            var result = new BooksAndCategoriesContract
            {
                BookType   = AreaBookType,
                Categories = categories,
                Books      = booksResult,
            };

            return(result);
        }
예제 #2
0
        protected override void ExecuteWorkImplementation()
        {
            foreach (var bookType in BookTypeHelper.GetBookTypeEnumsWithCategories())
            {
                var category = m_categoryRepository.GetCategoryByExternalId((short)bookType);

                var forum = m_forumRepository.GetForumByExternalCategoryIdAndCategory(m_oldCategory.Id, category.CategoryID);
                forum.Name = m_updatedCategory.Description;

                if (m_oldCategory.ParentCategoryId != m_updatedCategory.ParentCategoryId)
                {
                    forum.ParentForum = m_updatedCategory.ParentCategoryId == null
                        ? null
                        : m_forumRepository.GetForumByExternalCategoryIdAndCategory((int)m_updatedCategory.ParentCategoryId, category.CategoryID);
                }

                m_forumRepository.Update(forum);
            }
        }
예제 #3
0
        protected override void ExecuteWorkImplementation()
        {
            foreach (var bookType in BookTypeHelper.GetBookTypeEnumsWithCategories())
            {
                var category = m_categoryRepository.GetCategoryByExternalId((short)bookType);

                Forum parentForum = null;
                if (m_category.ParentCategoryId != null)
                {
                    parentForum = m_forumRepository.GetForumByExternalCategoryIdAndCategory((int)m_category.ParentCategoryId, category.CategoryID);
                }

                var forum = new Forum(m_category.Description, category, (short)ForumTypeEnum.SubCategory)
                {
                    ExternalId  = m_category.Id,
                    ParentForum = parentForum
                };
                m_forumRepository.Create(forum);
                m_forumAccessSubwork.SetAdminAccessToForumForAdminGroup(forum);
            }
        }
예제 #4
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);
            }
        }