public async Task <IActionResult> Index(EditCourseSaveViewModel model) { if (model.CourseId.HasValue) { var courseForEdit = await _courseService.GetCourseByIdAsync(new GetCourseByIdCriteria(model.CourseId.Value)); if (courseForEdit.IsSuccess) { courseForEdit.Value.CourseDescription = model?.CourseFor; courseForEdit.Value.EntryRequirements = model?.EntryRequirements; courseForEdit.Value.WhatYoullLearn = model?.WhatWillLearn; courseForEdit.Value.HowYoullLearn = model?.HowYouWillLearn; courseForEdit.Value.WhatYoullNeed = model?.WhatYouNeed; courseForEdit.Value.HowYoullBeAssessed = model?.HowAssessed; courseForEdit.Value.WhereNext = model?.WhereNext; courseForEdit.Value.AdultEducationBudget = model.AdultEducationBudget; courseForEdit.Value.AdvancedLearnerLoan = model.AdvancedLearnerLoan; courseForEdit.Value.IsValid = true; // The same for Live, BulkUpload, Migration courseForEdit.Value.UpdatedBy = User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(); // User.Identity.Name; courseForEdit.Value.UpdatedDate = DateTime.Now; courseForEdit.Value.ValidationErrors = _courseService.ValidateCourse(courseForEdit.Value).Select(x => x.Value); if (model.Mode == PublishMode.Migration) { if (!(courseForEdit.Value.ValidationErrors != null && courseForEdit.Value.ValidationErrors.Any())) { // Change courseruns status of MigrationReadyToGoLive to Live so the entire course can go live foreach (var courseRun in courseForEdit.Value.CourseRuns.Where(x => x.RecordStatus == RecordStatus.MigrationReadyToGoLive)) { courseRun.RecordStatus = RecordStatus.Live; } } } var message = string.Empty; bool isCourseValid = !(courseForEdit.Value.ValidationErrors != null && courseForEdit.Value.ValidationErrors.Any()); RecordStatus[] validStatuses = new[] { RecordStatus.MigrationReadyToGoLive, RecordStatus.Live }; if (isCourseValid && !(courseForEdit.Value.CourseRuns.Where(x => !validStatuses.Contains(x.RecordStatus)).Any())) { // Course run was fixed message = $"'{courseForEdit.Value.QualificationCourseTitle}' was successfully fixed and published."; } else { // Course was fixed message = $"'{courseForEdit.Value.QualificationCourseTitle}' was successfully fixed."; } var updatedCourse = await _courseService.UpdateCourseAsync(courseForEdit.Value); switch (model.Mode) { case PublishMode.Migration: return(RedirectToAction("Index", "PublishCourses", new { publishMode = model.Mode, courseId = model.CourseId, notificationTitle = message })); case PublishMode.BulkUpload: return(RedirectToAction("Index", "PublishCourses", new { publishMode = model.Mode, courseId = model.CourseId })); case PublishMode.Summary: TempData[TempDataKeys.ShowCourseUpdatedNotification] = true; return(RedirectToAction("Index", "CourseSummary", new { courseId = model.CourseId, courseRunId = model.CourseRunId })); default: return(RedirectToAction("Courses", "Provider", new { NotificationTitle = "Course edited", NotificationMessage = "You edited", qualificationType = courseForEdit.Value.QualificationType, courseId = updatedCourse.Value.id })); } } } return(View("Error", new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); }
public async Task <IActionResult> Index(EditCourseSaveViewModel model) { if (!model.CourseId.HasValue) { return(BadRequest()); } var courseId = model.CourseId.Value; var validationResult = new EditCourseSaveViewModelValidator().Validate(model); if (!validationResult.IsValid) { return(BadRequest()); } var updateResult = await _sqlQueryDispatcher.ExecuteQuery(new UpdateCourse() { CourseId = courseId, WhoThisCourseIsFor = model.CourseFor, EntryRequirements = model.EntryRequirements, WhatYoullLearn = model.WhatWillLearn, HowYoullLearn = model.HowYouWillLearn, WhatYoullNeed = model.WhatYouNeed, HowYoullBeAssessed = model.HowAssessed, WhereNext = model.WhereNext, UpdatedBy = _currentUserProvider.GetCurrentUser(), UpdatedOn = _clock.UtcNow }); if (!(updateResult.Value is Success)) { return(BadRequest()); } var course = await _sqlQueryDispatcher.ExecuteQuery(new GetCourse() { CourseId = courseId }); switch (model.Mode) { case PublishMode.Summary: TempData[TempDataKeys.ShowCourseUpdatedNotification] = true; return(RedirectToAction("Index", "CourseSummary", new { courseId = model.CourseId, courseRunId = model.CourseRunId })); default: return(RedirectToAction("Courses", "Provider", new { NotificationTitle = "Course edited", NotificationMessage = "You edited", qualificationType = course.LearnAimRefTypeDesc, courseId = courseId })); } }