Beispiel #1
0
        public async Task <JsonResult> CreateLesson([FromBody] CreateLessonRequestViewModel request)
        {
            var course = await _courseService.GetCourseById(request.CourseId);

            if (course == null)
            {
                throw new InvalidCourseIdException();
            }

            var model = await _lessonService.CreateLesson(request.Title, request.Content, course, request.Date);

            var result = new LessonViewModel(model);

            return(Json(result));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([FromBody] CreateLessonRequest lessonRequest)
        {
            var lesson = new Lesson
            {
                Id     = Guid.NewGuid().ToString(),
                Class  = lessonRequest.Class,
                Code   = lessonRequest.Code,
                Name   = lessonRequest.Name,
                Day    = lessonRequest.Day,
                Time   = lessonRequest.Time,
                UserId = HttpContext.GetUserId()
            };

            await _LessonService.CreateLesson(lesson);

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.Lesson.Get.Replace("{lessonId}", lesson.Id);

            return(Created(locationUri, lesson));
        }