public async Task<ActionResult> Upload(FileUploadViewModel model) { int t1 = Thread.CurrentThread.ManagedThreadId; List<Employee> employees = await Task.Factory.StartNew<List<Employee>> (() => GetEmployees(model)); int t2 = Thread.CurrentThread.ManagedThreadId; EmployeeBusinessLayer bal = new EmployeeBusinessLayer(); bal.UploadEmployees(employees); EmployeeListViewModel vm = new EmployeeListViewModel(); vm.Employees = new List<EmployeeViewModel>(); foreach (Employee item in employees) { EmployeeViewModel evm = new EmployeeViewModel(); evm.EmployeeName = item.FirstName + " " + item.LastName; evm.Salary = item.Salary.Value.ToString("C"); if (item.Salary > 15000) { evm.SalaryColor = "yellow"; } else { evm.SalaryColor = "green"; } vm.Employees.Add(evm); } return Json(vm); }
public ActionResult Index() { EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); List<Employee> employees = empBal.GetEmployees(); EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>(); foreach (Employee emp in employees) { EmployeeViewModel empViewModel = new EmployeeViewModel(); empViewModel.EmployeeId = emp.EmployeeId; empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName; empViewModel.Salary = emp.Salary.Value.ToString("C"); empViewModel.SalaryColor = emp.Salary > 15000 ? "yellow" : "green"; empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; return View("Index", employeeListViewModel); }