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 = PermissionService.GetPermissions(category, _usersRole, MemberService, CategoryPermissionService);

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

                    var isSubscribed = UserIsAuthenticated && (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 = PermissionService.GetPermissions(subCategory, _usersRole, MemberService, CategoryPermissionService);
                            subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet);
                        }
                        viewModel.SubCategories = subCatViewModel;
                    }

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

                return(ErrorToHomePage(Lang("Errors.NoPermission")));
            }
        }
        public void UnSubscribe(UnSubscribeEmailViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        // Add logic to add subscr
                        var isCategory = subscription.SubscriptionType.Contains("category");
                        var id         = subscription.Id;

                        if (isCategory)
                        {
                            // get the category
                            var cat = CategoryService.Get(Convert.ToInt32(id));

                            if (cat != null)
                            {
                                // get the notifications by user
                                var notifications = CategoryNotificationService.GetByUserAndCategory(CurrentMember, cat);

                                if (notifications.Any())
                                {
                                    foreach (var categoryNotification in notifications)
                                    {
                                        // Delete
                                        CategoryNotificationService.Delete(categoryNotification);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // get the topic
                            var topic = TopicService.Get(new Guid(id));

                            if (topic != null)
                            {
                                // get the notifications by user
                                var notifications = TopicNotificationService.GetByUserAndTopic(CurrentMember, topic);

                                if (notifications.Any())
                                {
                                    foreach (var topicNotification in notifications)
                                    {
                                        // Delete
                                        TopicNotificationService.Delete(topicNotification);
                                    }
                                }
                            }
                        }

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        throw new Exception(Lang("Errors.GenericMessage"));
                    }
                }
            }
            else
            {
                throw new Exception(Lang("Errors.GenericMessage"));
            }
        }