public ActionResult BulkLoad() { var students = new List<Student>(); var _bulkLoadService = new BulkLoadService(); _bulkLoadService.Load(students); return View(); }
public ActionResult UploadCoursesFile() { if (Request.Files.Count > 0) { var courses = new List<Course>(); HttpPostedFileBase file = Request.Files[0]; var reader = new StreamReader(file.InputStream); do { string line = reader.ReadLine(); var values = line.Split('|'); if (values.Count() == 2) { var course = new Course { Code = values[0], Name = values[1] }; courses.Add(course); } } while (reader.Peek() != -1); reader.Close(); var _bulkLoadService = new BulkLoadService(); _bulkLoadService.Load(courses); } return RedirectToAction("Index"); }
public ActionResult UploadStudentsFile() { if (Request.Files.Count > 0) { var students = new List<Student>(); validCourses = db.Courses.ToList(); HttpPostedFileBase file = Request.Files[0]; var reader = new StreamReader(file.InputStream); do { string line = reader.ReadLine(); var studentInfo = line.Split('|'); if (studentInfo.Count() == 4) { var student = new Student { ExternalId = int.Parse(studentInfo[0]), FirstName = studentInfo[1], LastName = studentInfo[2] }; var enrollementInfo = studentInfo[3].Split(','); if (enrollementInfo.Length > 0) { student.Enrollments = new List<Enrollment>(); foreach (var enrollementItem in enrollementInfo) { var enrollement = PraseEnrollement(enrollementItem); if (enrollement != null) { student.Enrollments.Add(enrollement); } } } students.Add(student); } } while (reader.Peek() != -1); reader.Close(); var _bulkLoadService = new BulkLoadService(); _bulkLoadService.Load(students); } return RedirectToAction("Index"); }