/// <summary> /// Get list project with conditions except selected project /// </summary> /// <param name="projectId">selected project id</param> /// <param name="request">conditions for filter</param> /// <returns>list project matching with conditions</returns> private IEnumerable <portal_Projects> GetRelatedProjects(int projectId, GetProjectWithConditionsRequest request) { var searchQuery = PredicateBuilder.True <portal_Projects>(); if (request.ProjectType != null) { searchQuery = searchQuery.And(p => p.Type == (int)request.ProjectType); } if (request.Region != null) { searchQuery = searchQuery.And(p => p.Region == (int)request.Region); } if (request.ProgressStatus != null) { searchQuery = searchQuery.And(p => p.ProgressStatus == (int)request.ProgressStatus); } if (request.SearchString != null && request.SearchString != string.Empty) { searchQuery = searchQuery.And(p => p.Name.Contains(request.SearchString)); } searchQuery = searchQuery.And(p => p.Id != projectId); IEnumerable <portal_Projects> projectsMatchingRefinement = db.Get( filter: searchQuery, includeProperties: "share_Images,cms_News,CoverImage"); return(projectsMatchingRefinement.ToList()); }
public IEnumerable <Model.Context.portal_Projects> GetRelatedProject(int?projectId) { try { var project = db.GetProjectById((int)projectId); if (project == null) { return(null); } GetProjectWithConditionsRequest request = new GetProjectWithConditionsRequest() { ProgressStatus = project.ProgressStatus, ProjectType = project.Type, Region = project.Region }; return(GetRelatedProjects((int)projectId, request).Take(3)); } catch (Exception ex) { return(null); // Log exceptions } }
public ActionResult GetProjectByRegion(int?region = null, string searchString = "", int page = 1) { GetProjectWithConditionsRequest request = new GetProjectWithConditionsRequest() { Index = page, NumberOfResultsPerPage = Portal.Infractructure.Utility.Define.DISPLAY_PROJECT_PAGE_SIZE, ProgressStatus = null, ProjectType = null, Region = region, SearchString = searchString }; GetProjectWithConditionResponse response = service.GetAllProjectMatchingConditions(request); IPagedList <portal_Projects> pageProjects = new StaticPagedList <portal_Projects>(response.Projects, page, Portal.Infractructure.Utility.Define.DISPLAY_PROJECT_PAGE_SIZE, response.TotalProjects); if (region != null) { ViewBag.Category = EnumHelper.GetDescriptionFromEnum((Define.Region)region); ViewBag.CategoryValue = region; } else { ViewBag.Category = "All"; ViewBag.CategoryValue = null; } ViewBag.CategoryType = Portal.Infractructure.Utility.Define.CategoryType.Region; return(View("DisplayProjects", pageProjects)); }
public GetProjectWithConditionResponse GetAllProjectMatchingConditions(GetProjectWithConditionsRequest request) { IEnumerable <portal_Projects> foundProjects = GetMatchingConditionProjects(request); GetProjectWithConditionResponse response = new GetProjectWithConditionResponse() { CurrentPage = request.Index, SearchString = request.SearchString, TotalNumberOfPages = (int)Math.Ceiling((double)foundProjects.Count() / request.NumberOfResultsPerPage), TotalProjects = foundProjects.Count(), Projects = CropProjectListToSatisfyGivenIndex(foundProjects, request.Index, request.NumberOfResultsPerPage) }; return(response); }
public ActionResult Index(string searchString = "", int page = 1) { GetProjectWithConditionsRequest request = new GetProjectWithConditionsRequest() { Index = page, NumberOfResultsPerPage = Portal.Infractructure.Utility.Define.DISPLAY_PROJECT_PAGE_SIZE, ProgressStatus = null, ProjectType = null, Region = null, SearchString = searchString }; GetProjectWithConditionResponse response = service.GetAllProjectMatchingConditions(request); IPagedList <portal_Projects> pageProjects = new StaticPagedList <portal_Projects>(response.Projects, page, Portal.Infractructure.Utility.Define.DISPLAY_PROJECT_PAGE_SIZE, response.TotalProjects); ViewBag.Category = "All Project"; ViewBag.CategoryValue = null; ViewBag.CategoryType = Portal.Infractructure.Utility.Define.CategoryType.All; return(View("DisplayProjects", pageProjects)); }