public ActionResult InsertMentors() { ViewBag.Message = "Insert Mentors"; //string path = "c:/MACA/mentors.txt"; string path = ""; //string path = ""; // To prevent bad actions! StreamReader srMentors = new StreamReader(path); List <Mentorship> lstMentors = new List <Mentorship>(); MentorshipsDbContext dbMentors = new MentorshipsDbContext(); PersonsDbContext dbPersons = new PersonsDbContext(); MentorshipTypeDbContext dbMentorshipType = new MentorshipTypeDbContext(); ThesisTypeDbContext dbThesisType = new ThesisTypeDbContext(); while (!srMentors.EndOfStream) { string[] lineArr = srMentors.ReadLine().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); Mentorship mentor = new Mentorship(); mentor.MentorshipID = Guid.NewGuid(); string personCode = lineArr[0].Trim(); mentor.PersonID = dbPersons.Persons.Where(x => x.AISID == personCode).First().PersonID; int mentortype = int.Parse(lineArr[1].Trim()); mentor.MentorshipTypeID = dbMentorshipType.MentorshipTypes.Where(x => x.AISCode == mentortype).First().MentorshipTypeID; mentor.Year = lineArr[2].Trim(); int thesistype = int.Parse(lineArr[3].Trim()); mentor.ThesisTypeID = dbThesisType.ThesisTypes.Where(x => x.AISCode == thesistype).First().ThesisTypeID; mentor.Student = lineArr[4].Trim() + " " + lineArr[5].Trim(); mentor.ThesisTitle = lineArr[6].Trim(); lstMentors.Add(mentor); } srMentors.Close(); // Insert Persons foreach (Mentorship mentor in lstMentors) { mentor.DateCreated = DateTime.Now; mentor.DateModified = DateTime.Now; mentor.UserCreatedID = new Guid(User.Identity.GetUserId()); mentor.UserModifiedID = mentor.UserCreatedID; dbMentors.Mentorships.Add(mentor); dbMentors.SaveChanges(); } return(RedirectToAction("Administration")); }