Exemplo n.º 1
0
        private async Task <Mock <ICourse> > CreateAndConfigureBaseCourseForUser(string courseId)
        {
            var baseCourse = new Mock <ICourse>();

            baseCourse.Setup(c => c.Id).Returns(courseId);
            await courseRolesRepo.ToggleRoleAsync(baseCourse.Object.Id, TestUsers.User.Id, CourseRoleType.CourseAdmin, TestUsers.Admin.Id, "Создал временный курс");

            await AuthenticateUserInControllerAsync(tempCourseController, TestUsers.User).ConfigureAwait(false);

            return(baseCourse);
        }
Exemplo n.º 2
0
        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.HasUserAccessToCourseAsync(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.ToggleRoleAsync(tmpCourseId, UserId, CourseRoleType.CourseAdmin, UserId, "Создал временный курс");

            return(new TempCourseUpdateResponse
            {
                Message = $"Временный курс с id {tmpCourseId} успешно создан.",
                LastUploadTime = loadingTime
            });
        }