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() { EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); // employeeListViewModel.UserName = User.Identity.Name; //New Line EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); List<Employee> employees = empBal.GetEmployees(); List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>(); foreach (Employee emp in employees) { EmployeeViewModel empViewModel = new EmployeeViewModel(); empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName; empViewModel.Salary = emp.Salary.Value.ToString("C"); if (emp.Salary > 15000) { empViewModel.SalaryColor = "yellow"; } else { empViewModel.SalaryColor = "green"; } empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; //employeeListViewModel.FooterData = new FooterViewModel(); //employeeListViewModel.FooterData.CompanyName = "StepByStepSchools";//Can be set to dynamic value //employeeListViewModel.FooterData.Year = DateTime.Now.Year.ToString(); return View("Index", employeeListViewModel); }
public ActionResult Index(int id) { var employeeListViewModel = new EmployeeListViewModel(); var empBal = new EmployeeBusinessLayer(); var employees = empBal.GetEmployees(); var empViewModels = new List<EmployeeViewModel>(); foreach (Employee emp in employees) { var empViewModel = new EmployeeViewModel(); empViewModel.EmployeeName = emp.FirstName + " " + emp.LastName; empViewModel.Salary = emp.Salary != null ? emp.Salary.Value.ToString("C") : ""; if (emp.Salary > 15000) empViewModel.SalaryColor = "yellow"; else empViewModel.SalaryColor = "green"; empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; //employeeListViewModel.UserName = "******"; return View("Index", employeeListViewModel); }
public ActionResult Index() { //Employee emp = new Employee(); //emp.FirstName = "gyk"; //emp.LastName = "alex"; //emp.Salary = 2000; //ViewBag.Employee = emp; //ViewBag和ViewData可以相互调用,底层数据结构是同一个 ////ViewData["Employee"] = emp;// 但这种类型并不好用,有安全和效率低的问题 //EmployeeViewModel vmEmployee = new EmployeeViewModel(); //vmEmployee.EmployeeName = emp.FirstName + " " + emp.LastName; //vmEmployee.Salary = emp.Salary.ToString("C"); //if (emp.Salary > 15000) //{ // vmEmployee.SalaryColor = "yellow"; //} //else //{ // vmEmployee.SalaryColor = "green"; //} EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel(); //employeeListViewModel.UserName = User.Identity.Name; EmployeeBusinessLayer empBal = new EmployeeBusinessLayer(); List<Employee> employees = empBal.GetEmployees(); List<EmployeeViewModel> empViewModels = new List<EmployeeViewModel>(); foreach (Employee item in employees) { EmployeeViewModel empViewModel = new EmployeeViewModel(); empViewModel.EmployeeName = item.FirstName + "*" + item.LastName; empViewModel.Salary = item.Salary.ToString(); if (item.Salary > 15000) { empViewModel.SalaryColor = "yellow"; } else { empViewModel.SalaryColor = "green"; } empViewModels.Add(empViewModel); } employeeListViewModel.Employees = empViewModels; //employeeListViewModel.FooterData = new FooterViewModel(); //employeeListViewModel.FooterData.CompanyName = "StepByStepSchools"; //employeeListViewModel.FooterData.Year = DateTime.Now.ToString(); return View("Index", employeeListViewModel); }