public async Task <IActionResult> GetLookupDataCacheData() { try { var authors = await _lookupDataRepository.GetAuthors(); var categories = await _lookupDataRepository.GetCategories(); var publishers = await _lookupDataRepository.GetPublishers(); // running the tasks in parallel -cant use this as AddDbContext is used and not set as transient // await Task.WhenAll(authors, categories, publishers); var model = new LookupDataCacheModel { Authors = authors, Catgegories = categories, Publishers = publishers }; return(Ok(model)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedGet", "Could not retrieve Authors data"); return(BadRequest(response)); } }
public async Task <IActionResult> DeleteAuthor(int id) { try { var status = await _lookupDataRepository.DeleteAuthor(id); return(Ok(status)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedUpadteAuthor", "Could not remove Author"); return(BadRequest(response)); } }
public async Task <IActionResult> AddAuthor([FromBody] LookupItemModel author) { try { var id = await _lookupDataRepository.CreateAuthor(author); return(Ok(id)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedAddAuthor", "Could not add Author"); return(BadRequest(response)); } }
public async Task <IActionResult> CreateAudioBook([FromBody] AudioBookItemModel model) { try { var audioBookDomain = _mapper.Map <Domain.AudioBook>(model); var audioBookId = await _audioBookRepository.CreateAudioBook(audioBookDomain); return(Ok(audioBookId)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedAddAudioBook", "Could not add a new audiobook"); return(BadRequest(response)); } }
public async Task <IActionResult> GetAudioBooks() { try { // get data from repo var data = await _audioBookRepository.GetAudioBooks(); // map to model var result = _mapper.Map <IEnumerable <AudioBookItemSummaryModel> >(data); return(Ok(result)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemSummaryModel> .BuildErrorResponse("FailedGet", "Could not retrieve all audiobooks info"); return(BadRequest(response)); } }
public async Task <IActionResult> UpdateAudioBook(int id, [FromBody] AudioBookItemModel model) { if (id != model.AudioBookId) { return(BadRequest()); } try { var audioBookDomain = _mapper.Map <Domain.AudioBook>(model); var status = await _audioBookRepository.UpdateAudioBook(audioBookDomain); return(Ok(status)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedAudioBookUpdate", "Could not update the audiobook"); return(BadRequest(response)); } }
public async Task <IActionResult> GetAudioBook(int id) { if (id == 0) { return(NotFound()); } try { // this._telemetry.TrackEvent(new EventTelemetry($"AudioBookController : GetAudioBook - Start retrieving audiobook with Id : {id }")); var data = await _audioBookRepository.GetAudioBookById(id); var result = _mapper.Map <AudioBookItemModel>(data); // this._telemetry.TrackEvent(new EventTelemetry($"AudioBookController : GetAudioBook - Finish retrieving audiobook with Id : {id}")); return(Ok(result)); } catch (Exception ex) { this._telemetry.TrackException(ex); var response = LookupResponse <AudioBookItemModel> .BuildErrorResponse("FailedGet", "Could not retrieve audiobook data"); return(BadRequest(response)); } }