Exemplo n.º 1
0
        public async Task<ActionResult> Upload(FileUploadViewModel model)
        {
            int t1 = Thread.CurrentThread.ManagedThreadId;
            List<Employee> employees = await Task.Factory.StartNew(() => GetEmployees(model));
            int t2 = Thread.CurrentThread.ManagedThreadId;

            EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
            ebl.UploadEmployees(employees);
            return RedirectToAction("Index", "Employee");
        }
Exemplo n.º 2
0
 List<Employee> GetEmployees(FileUploadViewModel model)
 {
     var 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;
 }