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"))); } }
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(id); if (cat != null) { // get the notifications by user var notifications = _categoryNotificationService.GetByUserAndCategory(LoggedOnUser, cat); if (notifications.Any()) { foreach (var categoryNotification in notifications) { // Delete _categoryNotificationService.Delete(categoryNotification); } } } } else { // get the topic var topic = _topicService.Get(id); if (topic != null) { // get the notifications by user var notifications = _topicNotificationService.GetByUserAndTopic(LoggedOnUser, topic); if (notifications.Any()) { foreach (var topicNotification in notifications) { // Delete _topicNotificationService.Delete(topicNotification); } } } } unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } } else { throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } }
public void UnSubscribe(EmailSubscriptionViewModel subscription) { if (Request.IsAjaxRequest()) { try { // Add logic to add subscr var isCategory = subscription.SubscriptionType.Contains("category"); var isTag = subscription.SubscriptionType.Contains("tag"); var id = subscription.Id; var dbUser = MembershipService.GetUser(User.Identity.Name); if (isCategory) { // get the category var cat = _categoryService.Get(id); if (cat != null) { // get the notifications by user var notifications = _categoryNotificationService.GetByUserAndCategory(dbUser, cat, true); if (notifications.Any()) { foreach (var categoryNotification in notifications) { // Delete _categoryNotificationService.Delete(categoryNotification); } } } } else if (isTag) { // get the tag var tag = _topicTagService.Get(id); if (tag != null) { // get the notifications by user var notifications = _tagNotificationService.GetByUserAndTag(dbUser, tag, true); if (notifications.Any()) { foreach (var n in notifications) { // Delete _tagNotificationService.Delete(n); } } } } else { // get the topic var topic = _topicService.Get(id); if (topic != null) { // get the notifications by user var notifications = _topicNotificationService.GetByUserAndTopic(dbUser, topic, true); if (notifications.Any()) { foreach (var topicNotification in notifications) { // Delete _topicNotificationService.Delete(topicNotification); } } } } Context.SaveChanges(); } catch (Exception ex) { Context.RollBack(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } else { throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } }