public void FillInSusiInfo(Student student, StudentInfo studentInfo, IEnumerable<CourseInfo> courseInfo) { // TODO: edit when SUSI API is available student.FirstName = studentInfo.FirstName; student.LastName = studentInfo.LastName; student.Email = "*****@*****.**"; Tuple<int, int> startEndYears = studentInfo.GetStartEndYear(); Bachelor bachelor = new Bachelor { StartYear = startEndYears.Item1, EndYear = startEndYears.Item2, Specialty = StudentManager.programmeMapping[studentInfo.Programme], Subjects = courseInfo.Select(x => x.ToSubject()).ToList(), }; FMIEdu fmiEdu = new FMIEdu { Bachelor = bachelor, }; student.FMIInfo = fmiEdu; db.SaveChanges(); }
public void FillInSusiInfo(Student student, StudentInfo studentInfo, IEnumerable<CourseInfo> courseInfo) { student.FirstName = studentInfo.FirstName; student.LastName = studentInfo.LastName; Tuple<int, int> startEndYears = studentInfo.GetStartEndYear(); Bachelor bachelor = new Bachelor { StartYear = startEndYears.Item1, EndYear = startEndYears.Item2, CurrentCourse = studentInfo.Year, Specialty = StudentManager.programmeMapping[studentInfo.Programme], Subjects = courseInfo.Select(x => x.ToSubject()).ToList(), CurrentAverageGrade = courseInfo.Average(x => x.Grade) }; FMIEdu fmiEdu = new FMIEdu { Bachelor = bachelor, }; student.FMIInfo = fmiEdu; db.SaveChanges(); }
public void AddStudent(int userId, StudentInfo studentInfo, IEnumerable<CourseInfo> courseInfo) { Student student = new Student(); student.UserId = userId; string imageFile = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/default-avatar.jpg")); byte[] buffer = File.ReadAllBytes(imageFile); student.Picture = buffer; this.FillInSusiInfo(student, studentInfo, courseInfo); db.Students.Add(student); db.SaveChanges(); }
public void AddStudent(int userId, StudentInfo studentInfo, IEnumerable<CourseInfo> courseInfo, string userName) { Student student = new Student(); student.UserId = userId; student.Email = userName + "@uni-sofia.com"; string imageFile = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/default-avatar.jpg")); byte[] buffer = File.ReadAllBytes(imageFile); student.Picture = buffer; this.FillInSusiInfo(student, studentInfo, courseInfo); db.Students.Add(student); try { db.SaveChanges(); } catch (Exception e) { throw; } }
private static StudentInfo ExtractStudentInfo(HtmlNode node) { // That table cell we just selected has a quite an interesting structure: // - some of the text is plain text put right inside the cell // - other parts are inside a span // - other parts are inside a span inside a span // - lastly, there are parts inside a span inside a strong StudentInfo info = new StudentInfo(); // The name is inside span inside span string[] names = node.SelectSingleNode("span/span").InnerText.Trim().Split(' '); info.FirstName = names[0]; info.MiddleName = names[1]; info.LastName = names[2]; // The other elements are inside span inside strong HtmlNodeCollection otherInfo = node.SelectNodes("strong/span"); info.FacultyNumber = otherInfo[0].InnerText.Trim(); info.Programme = otherInfo[1].InnerText.Trim(); // The following is true in case the student has dropped (the base) if (string.IsNullOrWhiteSpace(otherInfo[2].InnerHtml)) { info.Year = 0; info.Group = 0; } else { info.Year = Int32.Parse(otherInfo[2].InnerText.Replace("Курс", "").Trim()); info.Group = Int32.Parse(otherInfo[3].InnerText.Replace("Група", "").Trim()); } // I am too lazy to split this in temporary variables but the idea is to read a special word appended after the current year in SUSI string studentType = node.SelectNodes("span").Last().InnerText.Split(',')[1].Trim().ToUpperInvariant(); // Finally, the last of 'em magic stringz. // Check what we just got from the long line above for matches StudentType type; if (studentType == "БАКАЛАВРИ") type = StudentType.Bachelor; else if (studentType == "МАГИСТРИ") type = StudentType.Master; else type = StudentType.Doctor; info.Type = type; return info; }
/// <summary> /// Gets information about the currently logged in student from Susi. /// </summary> public StudentInfo GetStudentInfo() { if (this.Cookies.Count == 0) { throw new InvalidOperationException("You must login prior to getting info from SUSI"); } try { // AVADA KEDAVRA, DIE SUSI! HtmlDocument document = new HtmlDocument(); document.LoadHtml(this.GetHomePage()); string xpath = @"html/body/form/table[3]/tr/td[2]"; HtmlNode node = document.DocumentNode.SelectSingleNode(xpath); // That table cell we just selected has a quite an interesting structure: // - some of the text is plain text put right inside the cell // - other parts are inside a span // - other parts are inside a span inside a span // - lastly, there are parts inside a span inside a strong StudentInfo info = new StudentInfo(); // The name is inside span inside span string[] names = node.SelectSingleNode("span/span").InnerText.Trim().Split(' '); info.FirstName = names[0]; info.MiddleName = names[1]; info.LastName = names[2]; // The other elements are inside span inside strong HtmlNodeCollection otherInfo = node.SelectNodes("strong/span"); info.FacultyNumber = otherInfo[0].InnerText.Trim(); info.Programme = otherInfo[1].InnerText.Trim(); // The following is true in case the student has dropped (the base) if (string.IsNullOrWhiteSpace(otherInfo[2].InnerHtml)) { info.Year = 0; info.Group = 0; } else { info.Year = Int32.Parse(otherInfo[2].InnerText.Replace("Курс", "").Trim()); info.Group = Int32.Parse(otherInfo[3].InnerText.Replace("Група", "").Trim()); } // I am too lazy to split this in temporary variables but the idea is to read a special word appended after the current year in SUSI string studentType = node.SelectNodes("span").Last().InnerText.Split(',')[1].Trim().ToUpperInvariant(); // Finally, the last of 'em magic stringz. // Check what we just got from the long line above for matches StudentType type; if (studentType == "БАКАЛАВРИ") type = StudentType.Bachelor; else if (studentType == "МАГИСТРИ") type = StudentType.Master; else type = StudentType.Doctor; info.Type = type; return info; } catch (Exception e) { // In case something failed, throw a new exception throw new WebException("Can't load data from SUSI", e); } }