private List<Convict> FilterData(SearchParams searchParams) { using (var dataContext = new CrosoverTaskDataContex()) { IQueryable<Convict> filteredQueriable = dataContext.Convicts; if (searchParams.AgeStart.HasValue) { DateTime end = DateTime.Now.AddYears(-1 * searchParams.AgeStart.Value); filteredQueriable = filteredQueriable.Where(x => x.DateOfBirth < end); } if (searchParams.AgeEnd.HasValue) { DateTime start = DateTime.Now.AddYears(-1 * searchParams.AgeEnd.Value); filteredQueriable = filteredQueriable.Where(x => x.DateOfBirth > start); } if (searchParams.HeightStart.HasValue) { float start = searchParams.HeightStart.Value; filteredQueriable = filteredQueriable.Where(x => x.Height >= start); } if (searchParams.HeightEnd.HasValue) { float end = searchParams.HeightEnd.Value; filteredQueriable = filteredQueriable.Where(x => x.Height <= end); } if (searchParams.WeightStart.HasValue) { float start = searchParams.WeightStart.Value; filteredQueriable = filteredQueriable.Where(x => x.Weight >= start); } if (searchParams.WeightEnd.HasValue) { float end = searchParams.WeightEnd.Value; filteredQueriable = filteredQueriable.Where(x => x.Weight <= end); } if (searchParams.Name != null) { filteredQueriable = filteredQueriable.Where(x => x.FirstName.ToLower().Contains(searchParams.Name.ToLower())); } if (searchParams.Surname != null) { filteredQueriable = filteredQueriable.Where(x => x.LastName.ToLower().Contains(searchParams.Surname.ToLower())); } if (searchParams.Gender.HasValue) { filteredQueriable = filteredQueriable.Where(x => x.Gender == searchParams.Gender); } return filteredQueriable.Take(searchParams.MaxNumberOfResults).ToList(); } }
public BaseController() { DataContext = new CrosoverTaskDataContex(); ApplicationDbContext = new ApplicationDbContext(); UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(this.ApplicationDbContext)); }