// GET: StudentController/Edit/5 public ActionResult GetAssignment(string id, [FromServices] IGoogleAuthProvider auth) { var listCourseWorkResponse = new ListCourseWorkResponse(); string pageToken = null; do { var request = this.GetGoogleClassRoomService(auth).Courses.CourseWork.List(id); request.PageSize = 100; request.PageToken = pageToken; var response = request.Execute(); listCourseWorkResponse = response; } while (pageToken != null); List <Models.CourseWork> CourseWorkList = new List <Models.CourseWork>(); foreach (CourseWork item in listCourseWorkResponse.CourseWork) { CourseWorkList.Add( new Models.CourseWork() { CourseWorkId = item.Id, CourseId = id, Type = "Assigmment", Title = item.Title, Description = item.Description, }); } return(View(CourseWorkList)); }
private async Task FillInResourceAndOutcomesInfo(CancellationToken cancellationToken, ClassroomService classroomService, LtiRequest ltiRequest) { // Fill in the resource (courseWork) information if (!string.IsNullOrEmpty(ltiRequest.ContextId)) { var courseWorkRequest = classroomService.Courses.CourseWork.List(ltiRequest.ContextId); ListCourseWorkResponse courseWorkResponse = null; var thisPageUrl = HttpUtility.UrlDecode(Request.GetDisplayUrl()); do { if (courseWorkResponse != null) { courseWorkRequest.PageToken = courseWorkResponse.NextPageToken; } courseWorkResponse = await courseWorkRequest.ExecuteAsync(cancellationToken) .ConfigureAwait(false); var courseWork = courseWorkResponse.CourseWork?.FirstOrDefault(w => w.Materials.FirstOrDefault(m => m.Link.Url.Equals(thisPageUrl)) != null); if (courseWork != null) { ltiRequest.ResourceLinkId = courseWork.Id; ltiRequest.ResourceLinkTitle = courseWork.Title; ltiRequest.ResourceLinkDescription = courseWork.Description; // If this user is a student, and we have the AuthToken and RefreshToken for the teacher // that created the CourseWork, then accept outcomes if (ltiRequest.GetRoles().Contains(ContextRole.Learner) && courseWork.AssociatedWithDeveloper.HasValue && courseWork.AssociatedWithDeveloper.Value) { var googleUser = await _context.GoogleUsers .FindAsync(new object[] { courseWork.CreatorUserId }, cancellationToken) .ConfigureAwait(false); if (googleUser != null) { ltiRequest.LisOutcomeServiceUrl = new Uri($"{Request.Scheme}://{Request.Host}/outcomes").ToString(); var lisResultSourcedId = new LisResultSourcedId { CourseId = ltiRequest.ContextId, CourseWorkId = ltiRequest.ResourceLinkId, StudentId = ltiRequest.UserId, TeacherId = courseWork.CreatorUserId }; ltiRequest.LisResultSourcedId = JsonConvert.SerializeObject(lisResultSourcedId, Formatting.None); } } } } while (string.IsNullOrEmpty(ltiRequest.ResourceLinkId) && !string.IsNullOrEmpty(courseWorkResponse.NextPageToken)); } }
private static async Task <int> DescargarCursoAPI(CoursesResource.CourseWorkResource.ListRequest solicitud) { ListCourseWorkResponse r2 = await solicitud.ExecuteAsync(); if (r2.CourseWork != null) { foreach (var trabajo in r2.CourseWork) { Console.WriteLine("{0} / {1}", trabajo.Id, trabajo.Title); frmppal.DtGVTareas.Rows.Add(trabajo.Id, trabajo.Title); } } return(1); }
private async Task FillInContextAndResourceInfo(CancellationToken cancellationToken, ClassroomService classroomService, LtiRequest ltiRequest) { // Fill in the context (course) information if (AlternateCourseIdForSession != null) { var coursesRequest = classroomService.Courses.List(); coursesRequest.CourseStates = CoursesResource.ListRequest.CourseStatesEnum.ACTIVE; ListCoursesResponse coursesResponse = null; do { if (coursesResponse != null) { coursesRequest.PageToken = coursesResponse.NextPageToken; } coursesResponse = await coursesRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); if (coursesResponse.Courses != null) { foreach (var course in coursesResponse.Courses) { if (Uri.TryCreate(course.AlternateLink, UriKind.Absolute, out var alternateLink)) { var alternateCourseIdFromList = alternateLink.Segments[alternateLink.Segments.Length - 1]; if (alternateCourseIdFromList.Equals(AlternateCourseIdForSession)) { ltiRequest.ContextId = course.Id; ltiRequest.ContextTitle = course.Name; ltiRequest.ContextType = ContextType.CourseSection; break; } } } } } while (string.IsNullOrEmpty(ltiRequest.ContextId) && !string.IsNullOrEmpty(coursesResponse.NextPageToken)); } // Fill in the resource (courseWork) information if (!string.IsNullOrEmpty(ltiRequest.ContextId)) { var courseWorkRequest = classroomService.Courses.CourseWork.List(ltiRequest.ContextId); ListCourseWorkResponse courseWorkResponse = null; var thisPageUrl = Request.GetDisplayUrl(); do { if (courseWorkResponse != null) { courseWorkRequest.PageToken = courseWorkResponse.NextPageToken; } courseWorkResponse = await courseWorkRequest.ExecuteAsync(cancellationToken) .ConfigureAwait(false); var courseWorkItem = courseWorkResponse.CourseWork?.FirstOrDefault(w => w.Materials.FirstOrDefault(m => m.Link.Url.Equals(thisPageUrl)) != null); if (courseWorkItem != null) { ltiRequest.ResourceLinkId = courseWorkItem.Id; ltiRequest.ResourceLinkTitle = courseWorkItem.Title; ltiRequest.ResourceLinkDescription = courseWorkItem.Description; } } while (string.IsNullOrEmpty(ltiRequest.ResourceLinkId) && !string.IsNullOrEmpty(courseWorkResponse.NextPageToken)); } }
private async Task <List <ClassesViewModel> > GetClassesAsync() { string externalAccessToken = null; ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync(); if (User.Identity.IsAuthenticated) { var userFromManager = await _userManager.GetUserAsync(User); string authenticationMethod = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.AuthenticationMethod)?.Value; if (authenticationMethod != null) { externalAccessToken = await _userManager.GetAuthenticationTokenAsync(userFromManager, authenticationMethod, "access_token"); } else { externalAccessToken = await _userManager.GetAuthenticationTokenAsync(userFromManager, "Google", "access_token"); } GoogleCredential googleCredential = GoogleCredential.FromAccessToken(externalAccessToken); // Create Classroom API service. var service = new ClassroomService(new BaseClientService.Initializer() { HttpClientInitializer = googleCredential, ApplicationName = _configuration["ApplicationName"], }); // Define request parameters. CoursesResource.ListRequest request = service.Courses.List(); request.PageSize = 100; try { // List courses. ListCoursesResponse response = request.Execute(); var classes = new List <ClassesViewModel>(); if (response.Courses != null && response.Courses.Count > 0) { foreach (var course in response.Courses) { var courseWorksRequest = service.Courses.CourseWork.List(course.Id); ListCourseWorkResponse cwList = courseWorksRequest.Execute(); var studentsListRequest = service.Courses.Students.List(course.Id); ListStudentsResponse studentList = studentsListRequest.Execute(); classes.Add(new ClassesViewModel { Name = course.Name, Id = course.Id, Description = course.Description, CourseWorksCount = cwList?.CourseWork?.Count, StudentsCount = studentList?.Students?.Count }); } } return(classes); } catch (Exception err) { return(new List <ClassesViewModel>()); } } return(new List <ClassesViewModel>()); }