public PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel) { using (UnitOfWorkManager.NewUnitOfWork()) { // Get the topic var topic = _topicService.Get(getMorePostsViewModel.TopicId); var settings = SettingsService.GetSettings(); // Get the permissions for the category that this topic is in var permissions = RoleService.GetPermissions(topic.Category, UsersRole); // If this user doesn't have access to this topic then just return nothing if (permissions[SiteConstants.Instance.PermissionDenyAccess].IsTicked) { return null; } var orderBy = !string.IsNullOrEmpty(getMorePostsViewModel.Order) ? EnumUtils.ReturnEnumValueFromString<PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard; var posts = _postService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, settings.PostsPerPage, int.MaxValue, topic.Id, orderBy); var postIds = posts.Select(x => x.Id).ToList(); var votes = _voteService.GetVotesByPosts(postIds); var favs = _favouriteService.GetAllPostFavourites(postIds); var viewModel = new ShowMorePostsViewModel { Posts = ViewModelMapping.CreatePostViewModels(posts, votes, permissions, topic, LoggedOnReadOnlyUser, settings, favs), Topic = topic, Permissions = permissions }; return PartialView(viewModel); } }
public PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel) { // Get the topic var topic = _topicService.Get(getMorePostsViewModel.TopicId); // Get the permissions for the category that this topic is in var permissions = RoleService.GetPermissions(topic.Category, UsersRole); // If this user doesn't have access to this topic then just return nothing if (permissions[AppConstants.PermissionDenyAccess].IsTicked) { return(null); } var orderBy = !string.IsNullOrEmpty(getMorePostsViewModel.Order) ? EnumUtils.ReturnEnumValueFromString <PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard; var viewModel = new ShowMorePostsViewModel { Posts = _postService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, SettingsService.GetSettings().PostsPerPage, int.MaxValue, topic.Id, orderBy), Topic = topic, Permissions = permissions, User = LoggedOnUser }; return(PartialView(viewModel)); }
public PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel) { // Get the topic var topic = _topicService.Get(getMorePostsViewModel.TopicId); // Get the permissions for the category that this topic is in var permissions = RoleService.GetPermissions(topic.Category, UsersRole); // If this user doesn't have access to this topic then just return nothing if (permissions[AppConstants.PermissionDenyAccess].IsTicked) { return(null); } var orderBy = !string.IsNullOrEmpty(getMorePostsViewModel.Order) ? EnumUtils.ReturnEnumValueFromString <PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard; var posts = _postService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, SettingsService.GetSettings().PostsPerPage, int.MaxValue, topic.Id, orderBy); var postIds = posts.Select(x => x.Id).ToList(); var votes = _voteService.GetVotesByPosts(postIds); var favs = _favouriteService.GetAllPostFavourites(postIds); var viewModel = new ShowMorePostsViewModel { Posts = ViewModelMapping.CreatePostViewModels(posts, votes, permissions, topic, LoggedOnUser, SettingsService.GetSettings(), favs), Topic = topic, Permissions = permissions }; return(PartialView(viewModel)); }
public PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel) { // Get the topic var topic = ServiceFactory.TopicService.Get(getMorePostsViewModel.TopicId); // Get the permissions for the category that this topic is in var permissions = ServiceFactory.PermissionService.GetPermissions(topic.Category, _membersGroups); // If this user doesn't have access to this topic then just return nothing if (permissions[AppConstants.PermissionDenyAccess].IsTicked) { return(null); } var orderBy = !string.IsNullOrEmpty(getMorePostsViewModel.Order) ? AppHelpers.EnumUtils.ReturnEnumValueFromString <PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard; var viewModel = new ShowMorePostsViewModel { Topic = topic, Permissions = permissions, User = CurrentMember }; // Map the posts to the posts viewmodel // Get all favourites for this user var favourites = new List <Favourite>(); if (CurrentMember != null) { favourites.AddRange(ServiceFactory.FavouriteService.GetAllByMember(CurrentMember.Id)); } // Get the posts var posts = ServiceFactory.PostService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, Settings.PostsPerPage, int.MaxValue, topic.Id, orderBy); // Get all votes for all the posts var postIds = posts.Select(x => x.Id).ToList(); var allPostVotes = ServiceFactory.VoteService.GetAllVotesForPosts(postIds); viewModel.Posts = new List <ViewPostViewModel>(); foreach (var post in posts) { var postViewModel = PostMapper.MapPostViewModel(permissions, post, CurrentMember, Settings, topic, allPostVotes, favourites); viewModel.Posts.Add(postViewModel); } return(PartialView(PathHelper.GetThemePartialViewPath("AjaxMorePosts"), viewModel)); }
public virtual PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel) { var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService); var loggedOnUsersRole = loggedOnReadOnlyUser.GetRole(RoleService); // Get the topic var topic = _topicService.Get(getMorePostsViewModel.TopicId); var settings = SettingsService.GetSettings(); // Get the permissions for the category that this topic is in var permissions = RoleService.GetPermissions(topic.Category, loggedOnUsersRole); // If this user doesn't have access to this topic then just return nothing if (permissions[ForumConfiguration.Instance.PermissionDenyAccess].IsTicked) { return(null); } var orderBy = !string.IsNullOrWhiteSpace(getMorePostsViewModel.Order) ? EnumUtils.ReturnEnumValueFromString <PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard; var posts = Task.Run(() => _postService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, settings.PostsPerPage, int.MaxValue, topic.Id, orderBy)).Result; var postIds = posts.Select(x => x.Id).ToList(); var votes = _voteService.GetVotesByPosts(postIds); var favs = _favouriteService.GetAllPostFavourites(postIds); var viewModel = new ShowMorePostsViewModel { Posts = ViewModelMapping.CreatePostViewModels(posts, votes, permissions, topic, loggedOnReadOnlyUser, settings, favs), Topic = topic, Permissions = permissions }; return(PartialView(viewModel)); }