public IActionResult Index() { List <Employee> employees = _employeeDbContext.Employees.ToList(); EmployeeSearchResultViewModel model = new EmployeeSearchResultViewModel(); model.Employees = Mapper.Map <List <EmployeeViewModel> >(employees); return(View(model)); }
public IActionResult Search(EmployeeSearchResultViewModel model) { List <Employee> employees = _employeeDbContext.Employees.AsQueryable() .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.FirstName) || x.FirstName.Contains(model.EmployeeSearchParameters.FirstName)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.LastName) || x.LastName.Contains(model.EmployeeSearchParameters.LastName)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.Address) || x.Address.Contains(model.EmployeeSearchParameters.Address)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.Email) || x.Email.Contains(model.EmployeeSearchParameters.Email)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.Profession) || x.Profession.Contains(model.EmployeeSearchParameters.Profession)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.TelNumber) || x.PhoneNumber.Contains(model.EmployeeSearchParameters.TelNumber)) .Where(x => string.IsNullOrEmpty(model.EmployeeSearchParameters.Website) || x.Website.Contains(model.EmployeeSearchParameters.Website) ).ToList(); model.Employees = Mapper.Map <List <EmployeeViewModel> >(employees); return(View("Index", model)); }