예제 #1
0
        public Article CreateModel(ArticleDTO articleDto)
        {
            var      article    = _data.CreateModel(articleDto);
            Category categories = _unitOfWork.CategoryRepository.Find(q => q.Name == articleDto.Category.Name).ToList().FirstOrDefault();

            article.Category = categories ?? CategoryMapper.MapCategory(articleDto.Category);
            return(article);
        }
        /// <summary>
        /// Return all categories
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Category> GetAll()
        {
            const string cacheKey = "GetAllCategories";

            return((IEnumerable <Category>)ApplicationContext.Current.ApplicationCache.RequestCache.GetCacheItem(cacheKey, () =>
            {
                return CategoryMapper.MapCategory(_forumRootNode.Descendants(DialogueConfiguration.Instance.DocTypeForumCategory).ToList());
            }));
        }
예제 #3
0
        public override ActionResult Index(RenderModel model)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Get the category
                var category = CategoryMapper.MapCategory(model.Content, true);

                // Set the page index
                var pageIndex = AppHelpers.ReturnCurrentPagingNo();

                // check the user has permission to this category
                var permissions = ServiceFactory.PermissionService.GetPermissions(category, _usersRoles);

                if (!permissions[AppConstants.PermissionDenyAccess].IsTicked)
                {
                    var topics = ServiceFactory.TopicService.GetPagedTopicsByCategory(pageIndex,
                                                                                      Settings.TopicsPerPage,
                                                                                      int.MaxValue, category.Id);

                    var isSubscribed = UserIsAuthenticated && (ServiceFactory.CategoryNotificationService.GetByUserAndCategory(CurrentMember, category).Any());

                    // Create the main view model for the category
                    var viewModel = new ViewCategoryViewModel(model.Content)
                    {
                        Permissions  = permissions,
                        Topics       = topics,
                        Category     = category,
                        PageIndex    = pageIndex,
                        TotalCount   = topics.TotalCount,
                        User         = CurrentMember,
                        IsSubscribed = isSubscribed
                    };

                    // If there are subcategories then add then with their permissions
                    if (category.SubCategories.Any())
                    {
                        var subCatViewModel = new CategoryListViewModel
                        {
                            AllPermissionSets = new Dictionary <Category, PermissionSet>()
                        };
                        foreach (var subCategory in category.SubCategories)
                        {
                            var permissionSet = ServiceFactory.PermissionService.GetPermissions(subCategory, _usersRoles);

                            subCategory.LatestTopic = ServiceFactory.TopicService.GetPagedTopicsByCategory(1, Settings.TopicsPerPage, int.MaxValue, subCategory.Id).FirstOrDefault();
                            subCategory.TopicCount  = ServiceFactory.TopicService.GetTopicCountByCategory(subCategory.Id);
                            subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet);
                        }
                        viewModel.SubCategories = subCatViewModel;
                    }

                    return(View(PathHelper.GetThemeViewPath("Category"), viewModel));
                }

                return(ErrorToHomePage("No Permission"));
            }
        }
예제 #4
0
        public void PopulateCategories(IList <Topic> entityList)
        {
            // Map full categories
            var catIds = entityList.Select(x => x.CategoryId).ToList();
            var cats   = CategoryMapper.MapCategory(catIds);

            foreach (var entity in entityList)
            {
                var cat = cats.FirstOrDefault(x => x.Id == entity.CategoryId);
                entity.Category = cat;
            }
        }
        public List <Category> Get(List <int> ids)
        {
            var cats = new List <Category>();

            if (ids.Any())
            {
                var allCats = AppHelpers.UmbHelper().TypedContent(ids);
                foreach (var cat in allCats)
                {
                    cats.Add(CategoryMapper.MapCategory(cat));
                }
            }
            return(cats);
        }
 public async Task <ActionResult <IEnumerable <V1DTO.Category> > > GetCategoriesWithRestaurants()
 {
     return(Ok((await _bll.Categories.GetAllAsync()).Select(e => _mapper.MapCategory(e))));
 }
 /// <summary>
 /// Get all main categories (Categories with no parent category)
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Category> GetAllMainCategories()
 {
     return(CategoryMapper.MapCategory(_forumRootNode.Descendants(DialogueConfiguration.Instance.DocTypeForumCategory)
                                       .Where(x => x.Parent.DocumentTypeAlias != DialogueConfiguration.Instance.DocTypeForumCategory).ToList()));
 }
 public Category Get(int id, bool getSubAndParentCats = false)
 {
     return(CategoryMapper.MapCategory(AppHelpers.GetNode(id), getSubAndParentCats));
 }
예제 #9
0
 /// <summary>
 /// Get all main categories (Categories with no parent category)
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Category> GetAllMainCategories()
 {
     return(CategoryMapper.MapCategory(_forumRootNode.Descendants(AppConstants.DocTypeForumCategory)
                                       .Where(x => x.Parent.DocumentTypeAlias != AppConstants.DocTypeForumCategory).ToList()));
 }
예제 #10
0
 /// <summary>
 /// Return all categories
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Category> GetAll()
 {
     return(CategoryMapper.MapCategory(_forumRootNode.Descendants(AppConstants.DocTypeForumCategory).ToList()));
 }