public async Task <ActionResult> UpdateOptions(string courseId, int stepikCourseId) { var course = courseManager.GetCourse(courseId); var slides = course.Slides; var slidesXmls = slides.ToDictionary(s => s.Id, s => stepikRepo.GetSlideXmlIndicatedChanges(s)); /* TODO (andgein): following 5 lines are copy-paste*/ var returnUrl = Request.Url?.PathAndQuery ?? ""; var oauthAuthorizationUrl = OAuth.GetAuthorizationUrl(stepikClientId, GetStepikOAuthRedirectUri(), OAuth.EncryptState(returnUrl)); var client = await GetAuthenticatedStepikApiClient(); if (client == null) { return(Redirect(oauthAuthorizationUrl)); } var stepikCourse = await client.GetCourse(stepikCourseId); var stepikSections = new Dictionary <int, StepikApiSection>(); // TODO (andgein): download multiple sections in one request foreach (var sectionId in stepikCourse.SectionsIds) { stepikSections[sectionId] = await client.GetSection(sectionId); } var stepikUnitsIds = stepikSections.SelectMany(kvp => kvp.Value.UnitsIds); var stepikUnits = new Dictionary <int, StepikApiUnit>(); foreach (var unitId in stepikUnitsIds) { stepikUnits[unitId] = await client.GetUnit(unitId); } var stepikLessonsIds = stepikUnits.Select(kvp => kvp.Value.LessonId); var stepikLessons = new Dictionary <int, StepikApiLesson>(); foreach (var lessonId in stepikLessonsIds) { stepikLessons[lessonId] = await client.GetLesson(lessonId); } var slideStepMaps = stepikRepo.GetStepsExportedFromCourse(courseId, stepikCourseId); return(View(new UpdateOptionsModel { Course = course, DefaultXQueueName = defaultXQueueName, SlidesXmls = slidesXmls, StepikCourse = stepikCourse, StepikSections = stepikSections, StepikUnits = stepikUnits, StepikLessons = stepikLessons, SlideStepMaps = slideStepMaps, })); }
private async Task <ActionResult> SelectTarget(string courseId) { var returnUrl = Request.Url?.PathAndQuery ?? ""; var oauthAuthorizationUrl = OAuth.GetAuthorizationUrl(stepikClientId, GetStepikOAuthRedirectUri(), OAuth.EncryptState(returnUrl)); var client = await GetAuthenticatedStepikApiClient(); if (client == null) { return(Redirect(oauthAuthorizationUrl)); } var course = courseManager.GetCourse(courseId); var myCourses = await client.GetMyCourses(); return(View("SelectTarget", new SelectTargetModel { UlearnCourse = course, StepikCourses = myCourses.OrderBy(c => c.Id).ToList(), })); }
public async Task <ActionResult> InitialExport(string courseId, int stepikCourseId, string newLessonsSlidesIds, string xQueueName, string uploadVideo) { var returnUrl = Url.Action("InitialExportOptions", "Stepik", new { courseId = courseId, stepikCourseId = stepikCourseId }); /* TODO (andgein): following 4 lines are copy-paste*/ var oauthAuthorizationUrl = OAuth.GetAuthorizationUrl(stepikClientId, GetStepikOAuthRedirectUri(), OAuth.EncryptState(returnUrl)); var client = await GetAuthenticatedStepikApiClient(); if (client == null) { return(Redirect(oauthAuthorizationUrl)); } var exporter = new CourseExporter(client.AccessToken); var course = courseManager.GetCourse(courseId); var exportOptions = new CourseInitialExportOptions(stepikCourseId, xQueueName, ConvertStringToGuidList(newLessonsSlidesIds).ToList()) { VideoUploadOptions = (UploadVideoToStepikOption)Enum.Parse(typeof(UploadVideoToStepikOption), uploadVideo) }; var thread = new Thread(async() => await DoInitialExport(exporter, course, exportOptions)); thread.Start(); return(View("ExportStarted", course)); }
public async Task <ActionResult> UpdateCourse(string courseId, int stepikCourseId, string updateSlidesIds, string xQueueName, string uploadVideo) { var exportSlideAfterKey = "stepik__course-update__export-slide-after__"; var returnUrl = Url.Action("UpdateOptions", "Stepik", new { courseId = courseId, stepikCourseId = stepikCourseId }); /* TODO (andgein): following 4 lines are copy-paste*/ var oauthAuthorizationUrl = OAuth.GetAuthorizationUrl(stepikClientId, GetStepikOAuthRedirectUri(), OAuth.EncryptState(returnUrl)); var client = await GetAuthenticatedStepikApiClient(); if (client == null) { return(Redirect(oauthAuthorizationUrl)); } var exporter = new CourseExporter(client.AccessToken); var course = courseManager.GetCourse(courseId); var updateSlidesGuids = ConvertStringToGuidList(updateSlidesIds).ToList(); var slidesUpdateOptions = new List <SlideUpdateOptions>(); foreach (var slideId in updateSlidesGuids) { var stepsIdsForSlide = stepikRepo.GetStepsExportedFromSlide(courseId, stepikCourseId, slideId) .Select(m => m.StepId) .ToList(); var insertSlideAfterStepId = int.Parse(Request.Form[exportSlideAfterKey + slideId.GetNormalizedGuid()]); slidesUpdateOptions.Add(new SlideUpdateOptions(slideId, insertSlideAfterStepId, stepsIdsForSlide)); } var updateOptions = new CourseUpdateOptions( stepikCourseId, xQueueName, slidesUpdateOptions, new List <Guid>() ) { VideoUploadOptions = (UploadVideoToStepikOption)Enum.Parse(typeof(UploadVideoToStepikOption), uploadVideo) }; var thread = new Thread(async() => await DoUpdateCourse(exporter, course, updateOptions)); thread.Start(); return(View("UpdateStarted", course)); }