Example #1
0
        public async Task <IActionResult> UpdateSection(int sectionId, [FromBody] SectionUpdateRequestDto request)
        {
            try
            {
                var result = await _sectionServices.UpdateSectionAsync(sectionId, request);

                if (result == null)
                {
                    return(NotFound("no section found"));
                }
                return(Ok(result));
            }
            catch (NotFoundException error)
            {
                return(BadRequest(error.Message));
            }
            catch (CourseValidateException error)
            {
                return(BadRequest(error.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"UpdateSection() Error: {ex}");
                return(StatusCode(500, "Internal Server Error"));
            }
        }
Example #2
0
        public async Task <SectionDto> UpdateSectionAsync(int sectionId, SectionUpdateRequestDto request)
        {
            var user = await GetCurrentUser();

            if (user == null)
            {
                throw new NotFoundException("user not found");
            }
            var section = await _sectionRepository.GetSectionAsync(sectionId);

            if (section == null)
            {
                throw new NotFoundException("section not found");
            }
            section.Update(user, request.Title);
            await _sectionRepository.SaveAsync();

            return(Mapper.Map <SectionDto>(section));
        }