Ejemplo n.º 1
0
 private List<Employee> GetEmployees(FileUploadViewModel model)
 {
     List<Employee> employees = new List<Employee>();
     StreamReader csvReader = new StreamReader(model.fileUpload.InputStream);
     csvReader.ReadLine();       //assuming first line is header
     while(!csvReader.EndOfStream)
     {
         var line = csvReader.ReadLine();
         var values = line.Split(',');
         Employee e = new Employee();
         e.FirstName = values[0];
         e.LastName = values[1];
         e.Salary = int.Parse(values[2]);
         employees.Add(e);
     }
     return employees;
 }
Ejemplo n.º 2
0
 public async Task<ActionResult> Upload(FileUploadViewModel model)
 {
     int t1 = Thread.CurrentThread.ManagedThreadId;
     List<Employee> employees = await Task.Factory.StartNew<List<Employee>>(() => GetEmployees(model));
     EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
     ebl.UploadEmployees(employees);
     EmployeeListViewModel vm = new EmployeeListViewModel();
     vm.Employees = new List<EmployeeViewModel>();
     foreach (var item in employees)
     {
         EmployeeViewModel evm = new EmployeeViewModel();
         evm.EmployeeName = item.FirstName + " " + item.LastName;
         evm.Salary = item.Salary.ToString("c");
         evm.SalaryColor = item.Salary > 15000 ? "yellow" : "green";
         vm.Employees.Add(evm);
     }
     return Json(vm);
 }