public IQueryable <Project> Search(SearchProjectOptions options) { if (options == null) { return(null); } var query = GetAll() .AsQueryable(); if (!string.IsNullOrWhiteSpace(options.Title)) { query = query.Where(p => p.Title == options.Title); } if (!string.IsNullOrWhiteSpace(options.Description)) { query = query.Where(p => p.Description == options.Description); } if (options.ProjectId != null) { query = query.Where(p => p.ProjectId == options.ProjectId); } if (options.DateCreatedFrom != null) { query = query.Where(p => p.DateCreated >= options.DateCreatedFrom); } if (options.DateCreatedTo != null) { query = query.Where(p => p.DateCreated <= options.DateCreatedTo); } if (options.TargetFund != null) { query = query.Where(p => p.TargetFund >= options.TargetFund.Value); } if (options.CurrentFund != null) { query = query.Where(p => p.CurrentFund >= options.CurrentFund.Value); } if (!string.IsNullOrWhiteSpace(options.StringToFind)) { query = query.Where(p => p.Title.ToLower().Contains(options.StringToFind.ToLower()) || p.Description.ToLower().Contains(options.StringToFind.ToLower())); } if (options.category != null) { query = query.Where(p => p.Category == options.category); } query = query.Take(500); return(query); }
public List <Project> SearchProject( SearchProjectOptions projectOptions) { if (projectOptions == null) { return(null); } if (projectOptions.ProjectId == null && projectOptions.UserId == null) { return(null); } var query = context_ .Set <Project>() .AsQueryable(); if (projectOptions.UserId != 0) { query = query.Where( c => c.User.Id == projectOptions.UserId); } if (projectOptions.ProjectId != 0) { query = query.Where( c => c.Id == projectOptions.ProjectId); } if (!string.IsNullOrWhiteSpace(projectOptions.Description)) { query = query .Where(c => c.Description.Contains(projectOptions.Description)); } if (!string.IsNullOrWhiteSpace(projectOptions.Title)) { query = query .Where(c => c.Title.Contains(projectOptions.Title)); } //to be checked if (projectOptions.StatusProject == StatusProject.Available) { query = query .Where(c => c.StatusProject.Equals(projectOptions.StatusProject)); } if (!projectOptions.Category.Equals(ProjectCategory.Invalid)) { query = query .Where(c => c.StatusProject.Equals(projectOptions.StatusProject)); } return(query.ToList()); }
public IActionResult Search(SearchProjectOptions options) { var viewModel = new ProjectSearchViewModel() { ProjectList = projectService .SearchProject(options) .ToList() }; return(View(viewModel)); }
public ApiResult <Project> GetProjectById(int?id) { if (id == null) { return(ApiResult <Project> .Failed(StatusCode.BadRequest, "The Project Id is empty")); } var options = new SearchProjectOptions() { ProjectId = id }; return(ApiResult <Project> .Successful(SearchProjects(options).Data.SingleOrDefault())); }
public IActionResult Search(string searchType) { if (string.IsNullOrWhiteSpace(searchType)) { return(NotFound()); } var options = new SearchProjectOptions() { StringToFind = searchType }; var projects = _projectService.Search(options).ToList(); return(View(projects)); }
public IActionResult SearchByFilters([FromBody] SearchProjectOptions options) { var projects = projectService_ .SearchProjects(options) .Data .Include(x => x.Packages) .ToList(); var cfModel = new CfModel() { Projects = projects }; return(View(cfModel)); }
public IQueryable <Project> SearchProjects(SearchProjectOptions searchProjectOptions) { searchProjectOptions.SearchString = searchProjectOptions.SearchString?.Trim(); var number = 0; var query = _context .Set <Project>() .AsQueryable(); if (!string.IsNullOrWhiteSpace(searchProjectOptions.SearchString)) { if (Enum.TryParse(searchProjectOptions.SearchString, true, out Category category) && !int.TryParse(searchProjectOptions.SearchString, out number)) { query = query.Where( pj => pj.Title.ToLower().Contains(searchProjectOptions.SearchString.ToLower()) || pj.Description.ToLower() .Contains(searchProjectOptions.SearchString.ToLower()) || pj.Category == category); } else { query = query.Where( pj => pj.Title.ToLower().Contains(searchProjectOptions.SearchString.ToLower()) || pj.Description.ToLower() .Contains(searchProjectOptions.SearchString.ToLower())); } } if (searchProjectOptions.SingleCategoryId != null) { query = query.Where(p => (int)p.Category == searchProjectOptions.SingleCategoryId); } if (searchProjectOptions.CategoryIds != null) { query = query.Where(pj => searchProjectOptions.CategoryIds.Contains((int)pj.Category)); } return(query.Take(500)); }
public IQueryable <Project> SearchProject(SearchProjectOptions options) { if (options == null) { return(null); } var query = context_ .Set <Project>() .AsQueryable(); if (!string.IsNullOrWhiteSpace(options.Name)) { query = query.Where(p => p.Name.Contains(options.Name)); } if (!string.IsNullOrWhiteSpace(options.Description)) { query = query.Where(p => p.Description == options.Description); } if (options.ProjectId != null) { query = query.Where(p => p.ProjectId == options.ProjectId.Value); } if (options.Category != null && options.Category != 0) { query = query.Where(p => p.Category == options.Category); } query = query.Include(p => p.Photos) .Include(p => p.Videos) .Include(p => p.Posts) .Include(p => p.RewardPackages) .ThenInclude(p => p.Rewards) .Include(p => p.User); return(query); }
public IQueryable <Project> SearchProject(SearchProjectOptions options) { if (options == null) { return(null); } var query = dbContext .Set <Project>() .AsQueryable(); if (options.ProjectId != null) { query = query.Where(p => p.ProjectId == options.ProjectId); } if (options.Title != null) { query = query.Where(p => (p.Title == options.Title) || p.Title.Contains(options.Title)); } if (options.Description != null) { query = query.Where(p => p.Description == options.Description); } if (options.Category != null) { query = query.Where(p => p.Category == options.Category.Value); } if (options.UserId != null) { query = query.Where(p => p.UserId == options.UserId.Value); } return(query); }
public IActionResult Search(SearchProjectOptions options) { if (options == null) { return(BadRequest()); } var projects = projectService .SearchProject(options) .Include(p => p.Media) .Include(p => p.StatusUpdates) .Include(p => p.Packages) .Include(p => p.User) .ToList(); if (projects == null) { return(NotFound()); } //return Json(projects); return(View("Index", projects)); }
public IQueryable <Project> SearchProjects(SearchProjectOptions options) { if (options == null) { return(null); } var query = context_ .Set <Project>() .AsQueryable(); //Probably not used --> if (!string.IsNullOrWhiteSpace(options.Title)) { query = query.Where(c => c.Title == options.Title); } if (!string.IsNullOrWhiteSpace(options.Description)) { query = query.Where(c => c.Description == options.Description); } //<-- if (!string.IsNullOrWhiteSpace(options.SearchText)) { query = query.Where(c => c.Title.Contains(options.SearchText) || c.Description.Contains(options.SearchText)); } if (options.ProjectId != null) { query = query.Where(c => c.ProjectId == options.ProjectId.Value) .Include(a => a.AvailableRewards); //theloume to value? } if (options.DeadlineFrom != null) { query = query.Where(c => c.Deadline >= options.DeadlineFrom); } if (options.CreatedFrom != null) { query = query.Where(c => c.Created >= options.CreatedFrom); } if (options.Category != null) { query = query.Where(c => c.Category == options.Category.Value); } if (options.TotalFundFrom != null) { query = query.Where(c => c.TotalFund >= options.TotalFundFrom.Value); } if (options.CurrentFundFrom != null) { query = query.Where(c => c.CurrentFund == options.CurrentFundFrom.Value); } if (options.CreatorId != null) { var user = userService_.GetUserById(options.CreatorId.Value).Data; query = query.Where(c => user.Projects.Contains(c)); } if (options.BackerId != null) { var user = userService_.GetUserById(options.CreatorId.Value).Data; query = query.Where(c => user.Projects.Contains(c)); } if (options.RewardId != null) { query = query .Where(c => c.AvailableRewards.Any(a => a.RewardId == options.RewardId.Value)); } if (options.StatusUpdateId != null) { query = query .Where(c => c.StatusUpdates.Any(a => a.StatusUpdateId == options.StatusUpdateId.Value)); } query = query.Include(m => m.Media).Take(500); return(query); }
public ApiResult <IQueryable <Project> > SearchProjects(SearchProjectOptions options) { if (options == null) { return(ApiResult <IQueryable <Project> > .Failed(StatusCode.BadRequest, "Null options")); } var query = context_ .Set <Project>() .AsQueryable(); var queries = new List <IQueryable <Project> >(); if (options.ProjectId != null) { query = query.Where(p => p.ProjectId == options.ProjectId); } if (!string.IsNullOrWhiteSpace(options.Description)) { queries.Add(query.Where(p => p.Description.Contains(options.Description))); } if (options.Category != null) { queries.Add(query.Where(p => p.Category == options.Category)); } if (!string.IsNullOrWhiteSpace(options.Title)) { queries.Add(query.Where(p => p.Title.Contains(options.Title))); } if (!string.IsNullOrWhiteSpace(options.Photos)) { queries.Add(query.Where(p => p.Photos == options.Photos)); } if (!string.IsNullOrWhiteSpace(options.Videos)) { queries.Add(query.Where(p => p.Videos == options.Videos)); } if (!string.IsNullOrWhiteSpace(options.PostStatusUpdates)) { queries.Add(query.Where(p => p.PostStatusUpdates == options.PostStatusUpdates)); } if (options.CreatedFrom != null) { queries.Add(query.Where(c => c.Created >= (options.CreatedFrom))); } if (options.CreatedTo != null) { queries.Add(query.Where(c => c.Created <= options.CreatedTo)); } if (options.TotalAmountFrom != null) { queries.Add(query.Where(c => c.ProjectCost >= options.TotalAmountFrom)); } if (options.TotalAmountTo != null) { queries.Add(query.Where(c => c.ProjectCost <= options.TotalAmountTo)); } if (queries.Count > 0) { query = queries.Aggregate(query.Where(y => false), (q1, q2) => q1.Union(q2)); } return(ApiResult <IQueryable <Project> > .Successful(query.Take(500))); }