public IEnumerable <StudentPoco> Course(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); Mapper.CreateMap <Student, StudentPoco>(); var context = new StudentContext(); var students = (from s in context.Students where s.CourseIds.Every(id) select s).ToList(); foreach (var student in students) { try { var userJson = PearsonApiUtilities.GetUserJson(decodedToken, student.StudentId); var users = new JavaScriptSerializer().Deserialize <Users>(userJson); student.FirstName = users.users[0].firstName; student.LastName = users.users[0].lastName; } catch (Exception) { //skip it... HACK } } var result = Mapper.Map <List <Student>, IEnumerable <StudentPoco> >(students); return(result); }
// GET /api/students/5 public string GetStudent(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); return(PearsonApiUtilities.GetUserJson(decodedToken, id)); }
public List <StudentCourses.Course> Student(string token, string id) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); var decodedToken = PearsonApiUtilities.DecodeFrom64(token); var meCoursesJson = PearsonApiUtilities.XAuthApiCall(decodedToken, "http://m-api.ecollege.com/me/courses"); var meCourses = new JavaScriptSerializer().Deserialize <MeCourses>(meCoursesJson); var result = new List <StudentCourses.Course>(); foreach (var course in meCourses.courses) { foreach (var link in course.links) { var courseDetailJson = PearsonApiUtilities.XAuthApiCall(decodedToken, link.href); var courseDetail = new JavaScriptSerializer().Deserialize <StudentCourses>(courseDetailJson); result.Add(courseDetail.courses[0]); } } return(result); }