public async Task <IActionResult> Index(string searchString, string searchDepartment) { ViewData["CurrentFilter"] = searchString; ViewData["DepartmentFilter"] = searchDepartment; List <Employee> employeesList = new List <Employee>(); HttpClient client = _api.Initial(); HttpResponseMessage res = await client.GetAsync("api/employeedepartment"); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; employeesList = JsonConvert.DeserializeObject <List <Employee> >(result); } if (!String.IsNullOrEmpty(searchString)) { employeesList = employeesList.Where(emp => emp.FirstName.ToLower().Contains(searchString.ToLower().Trim()) || emp.LastName.ToLower().Contains(searchString.ToLower().Trim())).ToList(); } if (!String.IsNullOrEmpty(searchDepartment)) { employeesList = employeesList.Where(dept => dept.DepartmentName.ToLower().Contains(searchDepartment.ToLower().Trim()) || dept.SubDepartmentName.ToLower().Contains(searchDepartment.ToLower().Trim())).ToList(); } return(View(employeesList)); }
public async Task <IActionResult> Index() { List <Hotel> _hotels = new List <Hotel>(); HttpClient Client = _api.Initial(); // To get the initialization from thr domain HttpResponseMessage res = await Client.GetAsync("api/hotel2"); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; _hotels = JsonConvert.DeserializeObject <List <Hotel> >(result); } return(View(_hotels)); }
public async Task <List <EmployeeDTO> > GetAllAsync() { try { HelperAPI api = new HelperAPI(); List <EmployeeDTO> employeesResult = new List <EmployeeDTO>(); HttpClient client = api.Initial(); HttpResponseMessage response = await client.GetAsync("/api/Employees"); if (response.IsSuccessStatusCode) { var results = response.Content.ReadAsStringAsync().Result; employeesResult = JsonConvert.DeserializeObject <List <EmployeeDTO> >(results); } return(employeesResult); } catch (Exception ex) { throw; } }