示例#1
0
        public async Task <IActionResult> UpdateLesson(LessonForUpdateDto lessonForUpdateDto)
        {
            var lessonFromRepo = await _repo.GetLesson(lessonForUpdateDto.LessonId);

            _mapper.Map(lessonForUpdateDto, lessonFromRepo);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            throw new Exception("Nie udało się edytować wybranej lekcji");
        }
示例#2
0
        public async Task <IActionResult> Updatelesson(int id, LessonForUpdateDto LessonForUpdateDto)
        {
            var lessonFromRepo = await _repo.GetLesson(id);

            _mapper.Map(LessonForUpdateDto, lessonFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(Ok());
        }
示例#3
0
        public async Task <ActionResult <LessonForUpdateDto> > UpdateLesson(int adminId, int lessonId, [FromBody] LessonForUpdateDto lessonForUpdateDto)
        {
            var createdBy = await _repo.GetUser(adminId);

            if (createdBy.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var lessonsFromRepo = await _repo.GetLesson(lessonId);

            var updatedLesson = _mapper.Map(lessonForUpdateDto, lessonsFromRepo);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            throw new Exception("Zapisanie lekcji nie powiodło się");
        }