private async Task <Mock <ICourse> > CreateAndConfigureBaseCourseForUser(string courseId) { var baseCourse = new Mock <ICourse>(); baseCourse.Setup(c => c.Id).Returns(courseId); await courseRolesRepo.ToggleRole(baseCourse.Object.Id, TestUsers.User.Id, CourseRoleType.CourseAdmin, TestUsers.Admin.Id, "Создал временный курс"); await AuthenticateUserInControllerAsync(tempCourseController, TestUsers.User).ConfigureAwait(false); return(baseCourse); }
public async Task <ActionResult <TempCourseUpdateResponse> > CreateCourse([FromRoute] string courseId) { var tmpCourseId = GetTmpCourseId(courseId, UserId); if (!DontCheckBaseCourseExistsOnCreate && !await courseManager.HasCourseAsync(courseId)) { return(new TempCourseUpdateResponse { ErrorType = ErrorType.NotFound, Message = $"Не существует курса {courseId}" }); } if (!await courseRolesRepo.HasUserAccessToCourse(UserId, courseId, CourseRoleType.CourseAdmin)) { return(new TempCourseUpdateResponse { ErrorType = ErrorType.Forbidden, Message = $"Необходимо быть администратором курса {courseId}" }); } var tmpCourse = await tempCoursesRepo.FindAsync(tmpCourseId); if (tmpCourse != null) { return(new TempCourseUpdateResponse { ErrorType = ErrorType.Conflict, Message = $"Ваша временная версия курса {courseId} уже существует с id {tmpCourseId}." }); } var versionId = Guid.NewGuid(); var courseTitle = "Заготовка временного курса"; if (!courseManager.TryCreateTempCourse(tmpCourseId, courseTitle, versionId)) { throw new Exception(); } var result = await tempCoursesRepo.AddTempCourseAsync(tmpCourseId, UserId); var loadingTime = result.LoadingTime; await courseRolesRepo.ToggleRole(tmpCourseId, UserId, CourseRoleType.CourseAdmin, UserId, "Создал временный курс"); return(new TempCourseUpdateResponse { Message = $"Временный курс с id {tmpCourseId} успешно создан.", LastUploadTime = loadingTime }); }