public PartialViewResult GetSubscribedCategories() { var viewModel = new List<CategoryViewModel>(); using (UnitOfWorkManager.NewUnitOfWork()) { var categories = LoggedOnReadOnlyUser.CategoryNotifications.Select(x => x.Category); foreach (var category in categories) { var permissionSet = RoleService.GetPermissions(category, UsersRole); var topicCount = category.Topics.Count; var latestTopicInCategory = category.Topics.OrderByDescending(x => x.LastPost.DateCreated).FirstOrDefault(); var postCount = (category.Topics.SelectMany(x => x.Posts).Count() - 1); var model = new CategoryViewModel { Category = category, LatestTopic = latestTopicInCategory, Permissions = permissionSet, PostCount = postCount, TopicCount = topicCount, ShowUnSubscribedLink = true }; viewModel.Add(model); } } return PartialView(viewModel); }
public ActionResult Show(string slug, int? p) { using (UnitOfWorkManager.NewUnitOfWork()) { // Get the category var category = _categoryService.GetBySlugWithSubCategories(slug); // Allowed Categories for this user var allowedCategories = _categoryService.GetAllowedCategories(UsersRole); // Set the page index var pageIndex = p ?? 1; // check the user has permission to this category var permissions = RoleService.GetPermissions(category.Category, UsersRole); if (!permissions[SiteConstants.Instance.PermissionDenyAccess].IsTicked) { var topics = _topicService.GetPagedTopicsByCategory(pageIndex, SettingsService.GetSettings().TopicsPerPage, int.MaxValue, category.Category.Id); var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService, UsersRole, LoggedOnReadOnlyUser, allowedCategories, SettingsService.GetSettings()); // Create the main view model for the category var viewModel = new CategoryViewModel { Permissions = permissions, Topics = topicViewModels, Category = category.Category, PageIndex = pageIndex, TotalCount = topics.TotalCount, TotalPages = topics.TotalPages, User = LoggedOnReadOnlyUser, IsSubscribed = UserIsAuthenticated && (_categoryNotificationService.GetByUserAndCategory(LoggedOnReadOnlyUser, category.Category).Any()) }; // 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 = RoleService.GetPermissions(subCategory, UsersRole); subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet); } viewModel.SubCategories = subCatViewModel; } return View(viewModel); } return ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")); } }