Пример #1
0
        public async Task <LessonDetailViewModel> CreateLessonAsync(LessonCreateInputModel inputModel)
        {
            LessonDetailViewModel viewModel = await lessonService.CreateLessonAsync(inputModel);

            memoryCache.Remove($"Course{viewModel.CourseId}");
            return(viewModel);
        }
Пример #2
0
        public async Task <ActionResult> PostLesson(CreateLessonDto lessonDto)
        {
            var createdLesson = await _lessonService.CreateLessonAsync(lessonDto);

            if (createdLesson == null)
            {
                return(StatusCode(422, "Cannot create lesson"));
            }

            return(Ok(createdLesson));
        }
        public async Task <IActionResult> CreateLesson([Required, FromBody] LessonCreateDTO lessonCreateDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUserId = this.User.GetUserId().Value;
            var coachLessonId = lessonCreateDTO.CoachLessonId;

            lessonCreateDTO.StudentId = currentUserId;

            // Custom Validation
            if (!_coachLessonService.IsCoachLessonExists(coachLessonId))
            {
                return(NotFound());
            }
            if (_coachLessonService.IsUserOwnerOfCoachLesson(coachLessonId, currentUserId))
            {
                ModelState.AddModelError("CoachLessonId", "Nie można zapisać się na swoją lekcję.");
                return(BadRequest(ModelState));
            }
            if (!_coachLessonService.IsCoachLessonAvailable(coachLessonId))
            {
                ModelState.AddModelError("CoachLessonId", "Nie można zapisać się tę lekcję.");
                return(BadRequest(ModelState));
            }
            if (_coachLessonService.IsUserAlreadySignedUpForCoachLesson(coachLessonId, currentUserId))
            {
                ModelState.AddModelError("CoachLessonId", "Jesteś już zapisany na tę lekcję.");
                return(BadRequest(ModelState));
            }

            try
            {
                await _lessonService.CreateLessonAsync(lessonCreateDTO);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error during Lesson creation");
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(StatusCode((int)HttpStatusCode.Created));
        }
Пример #4
0
        public async Task <IActionResult> PostLesson([FromForm] LessonFormRequest request)
        {
            var user         = HttpContext.User.Claims.ElementAt(0);
            var memoryStream = new System.IO.MemoryStream();

            await request.Badge.CopyToAsync(memoryStream);

            var lesson = await _lessonService.CreateLessonAsync(
                uint.Parse(request.Type),
                uint.Parse(user.Value),
                request.Name,
                request.Description,
                memoryStream.ToArray()
                );

            var payload = new NamePayload
            {
                Id   = lesson.Id,
                Name = lesson.Name
            };

            return(Ok(payload));
        }