/// <summary> /// Get all projects assigned to a location /// </summary> /// <param name="location">Location</param> /// <param name="pageIndex">page index</param> /// <param name="pageSize">page size</param> /// <param name="categories">Selected categories</param> /// <param name="sortType">Sort by type</param> /// <param name="sortDirection">Sort by direction</param> /// <returns>Base project collection</returns> public IPaginatedList<Project> GetAllProjectsByLocationPaged(Location location = null, int pageIndex = 0, int pageSize = -1, IList<int> categories = null, ProjectSortType sortType = ProjectSortType.StartDate, ProjectSortDirection sortDirection = ProjectSortDirection.Ascending) { // Get the base projects var baseProjects = GetAllProjectsByLocationQuery(location, categories, sortType, sortDirection); var query = from p in _projectRepository.Table join b in baseProjects on p.Id equals b.Id orderby 1 ascending // needs order to paginate select p; var projects = new PaginatedList<Project>(query, pageIndex, pageSize); return projects; }
/// <summary> /// Get all projects assigned to a location /// </summary> /// <param name="location">Location</param> /// <param name="categories">Selected categories</param> /// <param name="sortType">Sort by type</param> /// <param name="sortDirection">Sort by direction</param> /// <returns>Base project query</returns> private IEnumerable<BaseProject> GetAllProjectsByLocationQuery(Location location = null, IList<int> categories = null, ProjectSortType sortType = ProjectSortType.StartDate, ProjectSortDirection sortDirection = ProjectSortDirection.Ascending) { var query = GetAllCachedProjects(); if (location != null) query = query.Where(p => p.Locations.Any(l => l.LocationId == location.Id)); if (categories != null && categories.Count > 0) query = query.Where(p => categories.All(x => p.Categories.Any(c => c.Id == x))); switch (sortDirection) { case ProjectSortDirection.Descending: switch (sortType) { case ProjectSortType.CreatedDate: query = query.OrderByDescending(x => x.CreatedDate); break; case ProjectSortType.Volunteers: query = query.OrderByDescending(x => x.Volunteers.Count); break; default: query = query.OrderByDescending(x => x.StartDate); break; } break; default: switch (sortType) { case ProjectSortType.CreatedDate: query = query.OrderBy(x => x.CreatedDate); break; case ProjectSortType.Volunteers: query = query.OrderBy(x => x.Volunteers.Count); break; default: query = query.OrderBy(x => x.StartDate); break; } break; } return query; }
/// <summary> /// Get all projects assigned to a location /// </summary> /// <param name="location">Location</param> /// <param name="categories">Selected categories</param> /// <param name="sortType">Sort by type</param> /// <param name="sortDirection">Sort by direction</param> /// <returns>Base project collection</returns> public IList<BaseProject> GetAllProjectsByLocation(Location location = null, IList<int> categories = null, ProjectSortType sortType = ProjectSortType.StartDate, ProjectSortDirection sortDirection = ProjectSortDirection.Ascending) { return GetAllProjectsByLocationQuery(location, categories, sortType, sortDirection).ToList(); }