public async Task <IActionResult> AddSubtitle([FromBody] SubtitleDTO subtitleDto) { if (!ModelState.IsValid || subtitleDto == null) { return(BadRequest(BaseStatusDto.CreateErrorDto("ModelState is not valid or the SubtitleDTO object is null."))); } try { Subtitle subtitle = _mapper.Map <Subtitle>(subtitleDto); await Task.Run(() => _subtitleService.AddSubtitle(subtitle)); subtitleDto.CreateSuccess("Subtitle record is created successfully."); return(Ok(subtitleDto)); } catch (Exception ex) { _logger.Debug($"{ex.GetType()} exception is generated."); _logger.Debug($"{ex.Message}"); return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message))); } }
public async Task <IActionResult> GetSubtitleById([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(BaseStatusDto.CreateErrorDto("Id of subtitle is incorrect."))); } Subtitle subtitle = _subtitleService.GetSubtitleById(id); if (subtitle == null) { return(BadRequest(BaseStatusDto.CreateErrorDto($"There is no a Subtitle record with Id = {id} in the Subtitles table."))); } SubtitleDTO subtitleDTO = _mapper.Map <SubtitleDTO>(subtitle); subtitleDTO.CreateSuccess("GET request by Subtitle Id succeeds."); return(Ok(subtitleDTO)); }
public async Task <IActionResult> GetSubtitleByPath([FromBody] string path) { if (!ModelState.IsValid || string.IsNullOrEmpty(path)) { return(BadRequest(BaseStatusDto.CreateErrorDto("The Path of the subtitle is incorrect."))); } Subtitle subtitle = _subtitleService.GetSubtitleByPath(path);//GetSubtitleByPath(path); if (subtitle == null) { return(BadRequest(BaseStatusDto.CreateErrorDto( $"There is no any Subtitle record with Path = {path} in the Subtitles table."))); } SubtitleDTO subtitleDTO = _mapper.Map <SubtitleDTO>(subtitle); subtitleDTO.CreateSuccess("GET request by Subtitle Path succeeds."); return(Ok(subtitleDTO)); }