public ActionResult InsertPeople() { ViewBag.Message = "Insert People"; //string path = "c:/MACA/persons-modified.txt"; string path = ""; // To prevent bad actions! StreamReader srPeople = new StreamReader(path); List <Person> lstPeople = new List <Person>(); while (!srPeople.EndOfStream) { string[] lineArr = srPeople.ReadLine().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); Person person = new Person(); person.PersonID = Guid.NewGuid(); person.AISID = lineArr[0].Trim(); person.Name = lineArr[1].Trim(); person.Surname = lineArr[2].Trim(); person.FullName = lineArr[3].Trim(); lstPeople.Add(person); } srPeople.Close(); // Insert Persons PersonsDbContext dbPersons = new PersonsDbContext(); AuthorsDbContext dbAuthors = new AuthorsDbContext(); foreach (Person person in lstPeople) { person.DateCreated = DateTime.Now; person.DateModified = DateTime.Now; person.UserCreatedID = User.Identity.GetUserId(); person.UserModifiedID = person.UserCreatedID; dbPersons.Persons.Add(person); dbPersons.SaveChanges(); // Automatically add a person to authors Author author = new Author(); author.AuthorID = Guid.NewGuid(); author.Surname = person.Surname; author.FirstName = person.Name; author.DateCreated = DateTime.Now; author.DateModified = DateTime.Now; author.UserCreatedID = new Guid(User.Identity.GetUserId()); author.UserModifiedID = author.UserCreatedID; dbAuthors.Authors.Add(author); dbAuthors.SaveChanges(); Person personTmp = dbPersons.Persons.Find(person.PersonID); personTmp.AuthorID = author.AuthorID; dbPersons.Entry(personTmp).State = EntityState.Modified; dbPersons.SaveChanges(); } return(RedirectToAction("Administration")); }
public static void AddPersonsToDb() { var dbContext = new PersonsDbContext(); var persons = PersonRepository.GetPersons(); foreach (var person in persons) { dbContext.Persons.Add(person); } dbContext.SaveChanges(); Console.WriteLine("Persons added"); }
public UnitOfWork( PersonsDbContext context, ICityRepository cityRepository, IPersonsRelationshipTypeRepository personsRelationshipTypeRepository, IPersonRepository personRepository, IPersonContactTypeRepository personContactTypeRepository ) { _context = context; CityRepository = cityRepository; PersonsRelationshipTypeRepository = personsRelationshipTypeRepository; PersonRepository = personRepository; PersonContactTypeRepository = personContactTypeRepository; }
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")); }
public RelatedPersonsServices(PersonsDbContext context) { _context = context; }
public PersonRepository(PersonsDbContext personDbContext) { _personDbContext = personDbContext; }
public PersonServices(PersonsDbContext context, IHostingEnvironment appEnvironment, IRelatedPersonServices relatedPersonsServices) { _context = context; _appEnvironment = appEnvironment; _relatedPersonsServices = relatedPersonsServices; }
public FileServices(PersonsDbContext context, IHostingEnvironment appEnvironment) { _context = context; _appEnvironment = appEnvironment; }
public ActionResult InsertSubjects() { ViewBag.Message = "Insert Subjects"; string path = "c:/MACA/teachings.txt"; //string path = ""; // To prevent bad actions! StreamReader srTeachings = new StreamReader(path); List <TMPSubject> lstTMPSubjects = new List <TMPSubject>(); while (!srTeachings.EndOfStream) { string[] lineArr = srTeachings.ReadLine().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); TMPSubject subject = new TMPSubject(); subject.TeacherCode = lineArr[0].Trim(); int sem = lineArr[1].Trim().ToLower() == "l" ? 2 : 1; subject.Semester = sem; subject.Year = lineArr[2].Trim(); subject.TeachingType = lineArr[3].Trim(); subject.HoursPerWeek = double.Parse(lineArr[4].Trim()); subject.SubjectCode = lineArr[5].Trim(); string depShort = lineArr[6].Trim(); string[] depShortSplit = depShort.Split('/'); subject.Department = depShortSplit[0].Trim(); subject.ShortName = depShortSplit[1].Trim(); subject.Name = lineArr[7].Trim(); if (lstTMPSubjects.Where(x => x.ShortName == subject.ShortName && x.Department == subject.Department && x.TeacherCode == subject.TeacherCode && x.TeachingType == subject.TeachingType && x.Year == subject.Year && x.Semester == subject.Semester && x.SubjectCode == subject.SubjectCode).Count() > 0) { lstTMPSubjects.Where(x => x.ShortName == subject.ShortName && x.Department == subject.Department && x.TeacherCode == subject.TeacherCode && x.TeachingType == subject.TeachingType && x.Year == subject.Year && x.Semester == subject.Semester && x.SubjectCode == subject.SubjectCode) .First().HoursPerWeek += subject.HoursPerWeek; } else { lstTMPSubjects.Add(subject); } } srTeachings.Close(); // Insert Persons PersonsDbContext dbPersons = new PersonsDbContext(); SubjectsDbContext dbSubjects = new SubjectsDbContext(); TeachingsDbContext dbTeachings = new TeachingsDbContext(); List <Subject> lstSubjects = new List <Subject>(); Dictionary <Guid, List <Teaching> > dicTeachings = new Dictionary <Guid, List <Teaching> >(); foreach (TMPSubject tmp in lstTMPSubjects) { if (lstSubjects.Where(x => x.ShortName == tmp.ShortName && x.Department == tmp.Department && x.Year == tmp.Year && x.Semester == tmp.Semester && x.AISCode == tmp.SubjectCode).Count() == 0) { Subject sub = new Subject(); sub.SubjectID = Guid.NewGuid(); sub.AISCode = tmp.SubjectCode; sub.Department = tmp.Department; sub.Name = tmp.Name; sub.Semester = tmp.Semester; sub.ShortName = tmp.ShortName; sub.AISCode = tmp.SubjectCode; sub.Year = tmp.Year; lstSubjects.Add(sub); Teaching t = new Teaching(); t.TeachingID = Guid.NewGuid(); t.Hours = tmp.HoursPerWeek; try { t.PersonID = dbPersons.Persons.Where(x => x.AISID == tmp.TeacherCode).First().PersonID; } catch { continue; } t.SubjectID = sub.SubjectID; t.TeachingTypeID = dbTeachings.TeachingTypes.Where(x => x.AISCode == tmp.TeachingType).First().TeachingTypeID; dicTeachings.Add(sub.SubjectID, new List <Teaching>()); dicTeachings[sub.SubjectID].Add(t); } else { Subject sub = lstSubjects.Where(x => x.ShortName == tmp.ShortName && x.Department == tmp.Department && x.Year == tmp.Year && x.Semester == tmp.Semester && x.AISCode == tmp.SubjectCode).First(); Teaching t = new Teaching(); t.TeachingID = Guid.NewGuid(); t.Hours = tmp.HoursPerWeek; try { t.PersonID = dbPersons.Persons.Where(x => x.AISID == tmp.TeacherCode).First().PersonID; } catch { continue; } t.SubjectID = sub.SubjectID; t.TeachingTypeID = dbTeachings.TeachingTypes.Where(x => x.AISCode == tmp.TeachingType).First().TeachingTypeID; dicTeachings[sub.SubjectID].Add(t); } } foreach (Subject sub in lstSubjects) { sub.DateCreated = DateTime.Now; sub.DateModified = DateTime.Now; sub.UserCreatedID = new Guid(User.Identity.GetUserId()); sub.UserModifiedID = sub.UserCreatedID; dbSubjects.Subjects.Add(sub); dbSubjects.SaveChanges(); if (dicTeachings.ContainsKey(sub.SubjectID)) { foreach (Teaching t in dicTeachings[sub.SubjectID]) { t.DateCreated = DateTime.Now; t.DateModified = DateTime.Now; t.UserCreatedID = new Guid(User.Identity.GetUserId()); t.UserModifiedID = t.UserCreatedID; dbTeachings.Teachings.Add(t); dbTeachings.SaveChanges(); } } } return(RedirectToAction("Administration")); }
public RelationRepository(PersonsDbContext c) : base(c, c.PersonalRelationships) { }
public PersonRepository(PersonsDbContext con) : base(con, con.Persons) { context = con; }
public PatientsDbService(PersonsDbContext context) { _context = context; }