public async Task <IHttpActionResult> GetWallList(WallsListFilter filter) { var wallList = await _wallService.GetWallsList(GetUserAndOrganization(), filter); var mappedWallList = _mapper.Map <IEnumerable <WallDto>, IEnumerable <WallListViewModel> >(wallList); return(Ok(mappedWallList)); }
public async Task <IHttpActionResult> GetAllPagedWall(WallsListFilter filter, int page = 1) { var userAndOrg = GetUserAndOrganization(); var wallPosts = await _wallService.GetAllPostsAsync(page, WebApiConstants.DefaultPageSize, userAndOrg, filter); var mappedPosts = _mapper.Map <IEnumerable <WallPostViewModel> >(wallPosts); var pagedViewModel = new PagedWallViewModel <WallPostViewModel> { PagedList = await mappedPosts.ToPagedListAsync(1, WebApiConstants.DefaultPageSize), PageSize = WebApiConstants.DefaultPageSize }; return(Ok(pagedViewModel)); }
private async Task <IEnumerable <WallDto> > GetAllOrNotFollowedWalls(UserAndOrganizationDTO userOrg, WallsListFilter filter) { var wallFilters = new Dictionary <WallsListFilter, Expression <Func <DataLayer.EntityModels.Models.Multiwall.Wall, bool> > > { { WallsListFilter.All, w => true }, { WallsListFilter.NotFollowed, w => w.Members.All(m => m.UserId != userOrg.UserId) } }; var walls = await _wallsDbSet .Include(w => w.Members) .Where(w => w.OrganizationId == userOrg.OrganizationId) .Where(wallFilters[filter]) .Where(w => w.Type == WallType.Main || w.Type == WallType.UserCreated) .OrderBy(x => x.Type) .ThenBy(w => w.Name.ToLower()) .Select(w => new WallDto { Id = w.Id, Name = w.Name, Description = w.Description, IsFollowing = w.Type == WallType.Main ? true : w.Members.Any(m => m.UserId == userOrg.UserId), Type = w.Type, Logo = w.Logo }) .ToListAsync(); return(walls); }
public async Task <IEnumerable <WallDto> > GetWallsList(UserAndOrganizationDTO userOrg, WallsListFilter filter) { var walls = filter == WallsListFilter.Followed ? await GetUserFollowedWalls(userOrg) : await GetAllOrNotFollowedWalls(userOrg, filter); await MapModeratorsToWalls(walls); return(walls); }
private async Task <IList <WallDto> > GetAllOrNotFollowedWallsAsync(UserAndOrganizationDto userOrg, WallsListFilter filter) { var wallFilters = new Dictionary <WallsListFilter, Expression <Func <MultiwallWall, bool> > > { { WallsListFilter.All, w => true }, { WallsListFilter.NotHiddenFromAllWalls, w => !w.IsHiddenFromAllWalls || w.Members.Any(m => m.UserId == userOrg.UserId) }, { WallsListFilter.NotFollowed, w => w.Members.All(m => m.UserId != userOrg.UserId) } }; var walls = await _wallsDbSet .Include(w => w.Members) .Where(w => w.OrganizationId == userOrg.OrganizationId) .Where(wallFilters[filter]) .Where(w => w.Type == WallType.Main || w.Type == WallType.UserCreated) .OrderBy(x => x.Type) .ThenBy(w => w.Name.ToLower()) .Select(w => new WallDto { Id = w.Id, Name = w.Name, Description = w.Description, // Don't simplify, since it's EF projection IsFollowing = w.Type == WallType.Main ? true : w.Members.Any(m => m.UserId == userOrg.UserId), Type = w.Type, Logo = w.Logo }) .ToListAsync(); return(walls); }
private async Task <IEnumerable <PostDto> > QueryForPostsAsync(UserAndOrganizationDto userOrg, int pageNumber, int pageSize, int?wallId, Expression <Func <Post, bool> > filter, WallsListFilter wallsListFilter) { if (filter == null) { filter = post => true; } List <int> wallsIds; if (wallId.HasValue && WallIsValid(userOrg, wallId.Value)) { wallsIds = new List <int> { wallId.Value }; } else { wallsIds = (await GetWallsListAsync(userOrg, wallsListFilter)).Select(w => w.Id).ToList(); } var entriesCountToSkip = (pageNumber - 1) * pageSize; var posts = await _postsDbSet .Include(post => post.Wall) .Include(post => post.Comments) .Where(post => wallsIds.Contains(post.WallId)) .Where(filter) .OrderByDescending(x => x.LastActivity) .Skip(() => entriesCountToSkip) .Take(() => pageSize) .ToListAsync(); var moderators = await _moderatorsDbSet.Where(x => wallsIds.Contains(x.WallId)).ToListAsync(); var watchedPosts = await RetrieveWatchedPostsAsync(userOrg.UserId, posts); var users = await GetUsersAsync(posts); return(MapPostsWithChildEntitiesToDto(userOrg.UserId, posts, users, moderators, watchedPosts)); }
public async Task <IEnumerable <PostDto> > GetAllPostsAsync(int pageNumber, int pageSize, UserAndOrganizationDto userOrg, WallsListFilter filter) { return(await QueryForPostsAsync(userOrg, pageNumber, pageSize, null, null, filter)); }