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 Upload(FileUploadViewModel model)
 {
     var employees = GetEmployees(model);
     var bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     return RedirectToAction("Index", "Employee");
 }
Esempio n. 3
0
 public async Task<ActionResult> Upload(FileUploadViewModel model)
 {
     int t1 = Thread.CurrentThread.ManagedThreadId;
     List<Employee> employees = await Task.Factory.StartNew<List<Employee>>(() => GetEmployees(model));
     //List<Employee> employees = GetEmployees(model);
     int t2 = Thread.CurrentThread.ManagedThreadId;
     EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     return RedirectToAction("Index", "Employee");
 }
 private List<Employee> GetEmployees(FileUploadViewModel model)
 {
     var employees = new List<Employee>();
     using (var reader = new StreamReader(model.fileUpload.InputStream))
     {
         reader.ReadLine(); //assuming first line is header
         while (!reader.EndOfStream)
         {
             var line = reader.ReadLine();
             var values = line.Split(',');
             var e = new Employee { FirstName = values[0], LastName = values[1], Salary = int.Parse(values[2]) };
             employees.Add(e);
         }
     }
     return employees;
 }
 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(',');//Values are comma separated
         Employee e = new Employee();
         e.FirstName = values[0];
         e.LastName = values[1];
         e.Salary = int.Parse(values[2]);
         employees.Add(e);
     }
     return employees;
 }