public static void WeekdayFetch() { Console.WriteLine("Weekday"); using (var db = new DASLContext()) { var schoolId = "16f79fbc-385b-4eb6-9466-977500d34432"; dynamic attendance = FetchData("SisService/StudentDailyAttendance?schoolInfoRefId=" + schoolId); for (var i = 0; i < attendance.count.Value; i++) { dynamic a = attendance.result[i]; string studentRefId = a.StudentPersonalRefId.Value; string absenceDate = a.Date.Value; DateTime date = DateTime.Parse(absenceDate); Student student = db.Students.SingleOrDefault(sc => sc.ExternalRefId == studentRefId); if (student == null) { Console.WriteLine("Unknown student, skipping..."); continue; } Absence existingAbsence = db.Absences.SingleOrDefault(ab => (ab.Student.ID == student.ID) && (ab.Date == date)); if (existingAbsence != null) { Console.WriteLine("Already recorded, skipping..."); continue; } Absence abObj = new Absence { Student = student, Date = date }; db.Absences.Add(abObj); db.SaveChanges(); } } }
public static void WeekendFetch() { // TODO Hopefully DASL will allow us to populate districts/classes/school/etc. automatically using (var db = new DASLContext()) { //dynamic studentsInSchool = FetchData("SisService/StudentPersonal?leaOrSchoolInfoRefId=" + schoolId); //Console.WriteLine(studentsInSchool.count.Value); //var found = 0; //for(var i = 0; i < studentsInSchool.count.Value; i++) //{ // dynamic s = studentsInSchool.result[i]; // //Console.WriteLine(s); // string fName = s.Name.FirstName.Value; // string lName = s.Name.LastName.Value; // Student existingStudent = db.Students.SingleOrDefault(sc => (sc.FirstName == fName) && (sc.LastName == lName)); // if(existingStudent != null) // { // found++; // existingStudent.ExternalRefId = s.RefId.Value; // db.SaveChanges(); // } //} //Console.WriteLine(found + "/490"); //Console.WriteLine("Fetching Schools For District (buc)"); //dynamic schoolsInDistrict = FetchData("GBService/buc/school"); //for (var i = 0; i < schoolsInDistrict.count.Value; i++) //{ // Console.WriteLine(schoolsInDistrict.result[i]); //dynamic s = schoolsInDistrict.result[i]; //School schoolObj = new School //{ // SchoolId = s.SchoolID.Value.ToString(), // DistrictSchoolId = s.DistrictSchoolID.Value, // SchoolName = s.SchoolName.Value, // PrincipalName = s.PrincipalName.Value, // Address = s.Address.Value, // City = s.City.Value, // State = s.State.Value, // ZIP = s.ZIP.Value, // PhoneNumber = s.PhoneNumber.Value, // ExternalRefId = s.ExternalRefId.Value //}; //School existingSchool = db.Schools.SingleOrDefault(sc => sc.SchoolId == schoolObj.SchoolId); //if (existingSchool == null) //{ // // Add it // db.Schools.Add(schoolObj); //} //else //{ // // Keep it up-to-date // existingSchool.SchoolId = schoolObj.SchoolId; // existingSchool.DistrictSchoolId = schoolObj.DistrictSchoolId; // existingSchool.SchoolName = schoolObj.SchoolName; // existingSchool.PrincipalName = schoolObj.PrincipalName; // existingSchool.PhoneNumber = schoolObj.PhoneNumber; // existingSchool.Address = schoolObj.Address; // existingSchool.City = schoolObj.City; // existingSchool.State = schoolObj.State; // existingSchool.ZIP = schoolObj.ZIP; // existingSchool.ExternalRefId = schoolObj.ExternalRefId; //} //db.SaveChanges(); //Console.WriteLine("Fetching Classes For School (" + schoolObj.SchoolId + ")"); //dynamic classesForSchool = FetchData("GBService/buc/class?SchoolID=" + schoolObj.SchoolId); //if (classesForSchool == null) //{ // // This school likely no longer exists // Console.WriteLine("School no longer exists (" + schoolObj.SchoolId + ")"); // continue; //} //Console.WriteLine(classesForSchool.count.Value + " Found"); /*for (var j = 0; j < classesForSchool.count.Value; j++) { dynamic c = classesForSchool.result[j]; Class classObj = new Class { DistrictCourseId = c.DistrictCourseID.Value, CourseName = c.CourseName.Value, SchoolId = c.SchoolID.Value.ToString(), ClassId = c.ClassID.Value.ToString(), CourseId = c.CourseID.Value.ToString(), ExternalRefId = c.ExternalRefId.Value }; Class existingClass = db.Classes.SingleOrDefault(cl => cl.ClassId == classObj.ClassId); if (existingClass == null) { // Add it db.Classes.Add(classObj); } else { // Keep it up-to-date existingClass.DistrictCourseId = classObj.DistrictCourseId; existingClass.CourseName = classObj.CourseName; existingClass.SchoolId = classObj.SchoolId; existingClass.ClassId = classObj.ClassId; existingClass.CourseId = classObj.CourseId; existingClass.ExternalRefId = classObj.ExternalRefId; } db.SaveChanges(); Console.WriteLine("Fetching Enrollment for Class (" + existingClass.ClassId + ")"); dynamic enrollmentForClass = FetchData("GBService/buc/classenrollment?ClassID=" + existingClass.ClassId); if (enrollmentForClass == null) { // This school likely no longer exists continue; } Console.WriteLine(enrollmentForClass.count.Value + " Found"); for (var k = 0; k < enrollmentForClass.count.Value; k++) { dynamic en = enrollmentForClass.result[k]; if (en["Students"] == null || en.Students.Count == 0) { Console.WriteLine("No students, skipping..."); continue; } for(var l = 0; l < en.Students.Count; l++) { dynamic st = en.Students[l]; Student studentObj = new Student { StudentId = st.StudentID.Value.ToString(), SchoolId = st.SchoolID.Value.ToString(), FirstName = st.FirstName.Value, MiddleName = st.MidName.Value, LastName = st.LastName.Value, Gender = st.Gender.Value, DOB = st.DateOfBirth.Value.ToString(), GradeLevel = st.GradeLevelID.Value.ToString(), ExternalRefId = st.ExternalRefId.Value }; Student existingStudent = db.Students.SingleOrDefault(sta => sta.StudentId == studentObj.StudentId); if (existingStudent == null) { // Add it db.Students.Add(studentObj); } else { // Keep it up-to-date existingStudent.SchoolId = studentObj.SchoolId; existingStudent.FirstName = studentObj.FirstName; existingStudent.MiddleName = studentObj.MiddleName; existingStudent.LastName = studentObj.LastName; existingStudent.GradeLevel = studentObj.GradeLevel; existingStudent.Gender = studentObj.Gender; existingStudent.DOB = studentObj.DOB; existingStudent.ExternalRefId = studentObj.ExternalRefId; } StudentClass studentClassObj = new StudentClass { StudentId = studentObj.StudentId, ClassId = classObj.ClassId }; StudentClass existingStudentClass = db.StudentClasses.SingleOrDefault(stCl => stCl.StudentId == studentObj.StudentId && stCl.ClassId == classObj.ClassId); if(existingStudentClass == null) { db.StudentClasses.Add(studentClassObj); } db.SaveChanges(); //Console.WriteLine("Fetching Assignments for Student (" + existingStudent.StudentId + ")"); dynamic assignmentsForStudent = FetchData("GBService/buc/assignmentscore?StudentID=" + existingStudent.StudentId); Console.WriteLine("GBService/buc/assignmentscore?StudentID=" + existingStudent.StudentId); if (assignmentsForStudent != null) { Console.WriteLine(assignmentsForStudent.ToString()); return; } else { return; } } } }*/ /*Console.WriteLine("Fetching Staff For School (" + schoolObj.RefId + ")"); dynamic staffForSchool = FetchData("SisService/Staff?leaOrSchoolInfoRefId=" + schoolObj.RefId); if (staffForSchool == null) { // This school likely no longer exists Console.WriteLine("School no longer exists (" + schoolObj.RefId + ")"); continue; } Console.WriteLine(staffForSchool.count.Value + " Found"); for (var k = 0; k < staffForSchool.count.Value; k++) { dynamic st = staffForSchool.result[k]; Staff staffObj = new Staff { RefId = st.RefId.Value, LocalId = st.LocalId.Value, StateProvinceId = st.StateProvinceId.Value, SchoolRefId = schoolObj.RefId, FirstName = st.Name.FirstName.Value, LastName = st.Name.LastName.Value }; if (st["EmailList"] != null && st.EmailList.Count > 0) { staffObj.Email = st.EmailList[0].Value; } Staff existingStaff = db.Staffs.SingleOrDefault(sta => sta.RefId == staffObj.RefId); if (existingStaff == null) { // Add it db.Staffs.Add(staffObj); } else { // Keep it up-to-date existingStaff.LocalId = staffObj.LocalId; existingStaff.StateProvinceId = staffObj.StateProvinceId; existingStaff.SchoolRefId = staffObj.SchoolRefId; existingStaff.FirstName = staffObj.FirstName; existingStaff.LastName = staffObj.LastName; existingStaff.Email = staffObj.Email; } db.SaveChanges(); } Console.WriteLine("Fetching Students For School (" + schoolObj.RefId + ")"); dynamic studentsForSchool = FetchData("SisService/StudentSnapshot?schoolInfoRefId=" + schoolObj.RefId); if (studentsForSchool == null) { // This school likely no longer exists continue; } Console.WriteLine(studentsForSchool.count.Value + " Found"); for (var k = 0; k < studentsForSchool.count.Value; k++) { dynamic st = studentsForSchool.result[k]; Student studentObj = new Student { RefId = st.StudentPersonalRefId.Value, LocalId = st.LocalId.Value, StateProvinceId = st.StateProvinceId.Value, SchoolRefId = schoolObj.RefId, FirstName = st.Name.FirstName.Value, MiddleName = st.Name.MiddleName.Value, LastName = st.Name.LastName.Value, HomeroomNumber = st.HomeEnrollment.HomeroomNumber.Value, GradeLevel = st.HomeEnrollment.GradeLevel.Code.Value }; Student existingStudent = db.Students.SingleOrDefault(sta => sta.RefId == studentObj.RefId); if (existingStudent == null) { // Add it db.Students.Add(studentObj); } else { // Keep it up-to-date existingStudent.LocalId = studentObj.LocalId; existingStudent.StateProvinceId = studentObj.StateProvinceId; existingStudent.SchoolRefId = studentObj.SchoolRefId; existingStudent.FirstName = studentObj.FirstName; existingStudent.MiddleName = studentObj.MiddleName; existingStudent.LastName = studentObj.LastName; existingStudent.HomeroomNumber = studentObj.HomeroomNumber; existingStudent.GradeLevel = studentObj.GradeLevel; } db.SaveChanges(); } Console.WriteLine("Fetching Rooms For School (" + schoolObj.RefId + ")"); dynamic roomsForSchool = FetchData("SisService/Room?leaOrSchoolInfoRefId=" + schoolObj.RefId); if (roomsForSchool == null) { // This school likely no longer exists continue; } Console.WriteLine(roomsForSchool.count.Value + " Found"); for (var k = 0; k < roomsForSchool.count.Value; k++) { dynamic r = roomsForSchool.result[k]; Room roomObj = new Room { RefId = r.RefId.Value, SchoolRefId = schoolObj.RefId, RoomNumber = r.RoomNumber.Value, Capacity = r.Capacity.Value.ToString() }; if (r["StaffList"] != null && r.StaffList["StaffPersonalRefId"] != null && r.StaffList.StaffPersonalRefId.Count > 0) { roomObj.StaffRefId = r.StaffList.StaffPersonalRefId[0].Value; } Room existingRoom = db.Rooms.SingleOrDefault(ro => ro.RefId == roomObj.RefId); if (existingRoom == null) { // Add it db.Rooms.Add(roomObj); } else { // Keep it up-to-date existingRoom.SchoolRefId = roomObj.SchoolRefId; existingRoom.StaffRefId = roomObj.StaffRefId; existingRoom.RoomNumber = roomObj.RoomNumber; existingRoom.Capacity = roomObj.Capacity; } db.SaveChanges(); }*/ //} } }