public Lesson CreatyLesson(CreateLessonDTO createLesson)
        {
            var lesson = new Lesson()
            {
                Cabinet = createLesson.Number,
                Subject = SubjectService.Get(SubjectService.GetAll().FirstOrDefault(x => x.Name == createLesson.Subject).Id),
            };

            Create(lesson);
            return(lesson);
        }
        public async Task<IActionResult> CreateLessonAsync([FromBody] CreateLessonRequest request)
        {
            if (request != null && ModelState.IsValid)
            {
                CreateLessonDTO createLessonDTO = new CreateLessonDTO 
                { 
                    Lesson = mapper.Map<LessonDTO>(request), 
                    TeacherEmail = User.Identity.Name 
                };

                if (await lessonService.AddLessonAsync(createLessonDTO))
                {
                    return Ok();
                }
            }

            return BadRequest();
        }
        //temporary returning boolean
        public async Task <bool> AddLessonAsync(CreateLessonDTO createLessonDTO)
        {
            //TODO: should return errors if category doesn't exist and/or
            //if the teacher who sent this request can't add lesson to the course they doesn`t belong to
            var course = await courseRepository.GetCourseByIdAsync(createLessonDTO.Lesson.CourseId);

            if (course != null && course.CourseMembers.FirstOrDefault(m => m.Teacher.User.Email == createLessonDTO.TeacherEmail) != null)
            {
                var lesson = mapper.Map <Lesson>(createLessonDTO.Lesson);
                await lessonRepository.AddAsync(lesson);

                await lessonRepository.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
 public IActionResult createLesson([FromBody] CreateLessonDTO request)
 => Ok(LessonService.CreatyLesson(request));