Exemplo n.º 1
0
 public ActionResult Upload(FileUploadViewModel model)
 {
     List<Employee> employees = GetEmployees(model);
     EmployeeBusinessLayer bal = new EmployeeBusinessLayer();
     bal.UploadEmployees(employees);
     return RedirectToAction("Index", "Employee");
 }
Exemplo n.º 2
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(',');//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;
 }