Example #1
0
        public void UploadStudents(IFormFile students)
        {
            Stream fileStream = students.OpenReadStream();

            using (StreamReader reader = new StreamReader(fileStream))
            {
                while (!reader.EndOfStream)
                {
                    string   line = reader.ReadLine();
                    string[] data = line.Split(',');
                    User     u    = new User {
                        FirstName     = data[0],
                        LastName      = data[1],
                        Email         = data[2],
                        Password      = data[3],
                        AccessLevelId = Convert.ToInt16(data[4])
                    };
                    int uId = _userFactory.AddUser(u);

                    Student s = new Student {
                        UserId      = uId,
                        StartDate   = Convert.ToDateTime(data[5]),
                        CurrStackId = Convert.ToInt16(data[7])
                    };
                    if (data[6] != "")
                    {
                        s.EndDate = Convert.ToDateTime(data[6]);
                    }
                    _userFactory.AddStudent(s);
                }
            }
        }