コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
 private void MapCategories(AudioBookItemModel model, AudioBook audioBook)
 {
     model.Categories = audioBook.AudioBookCategories.Select(c => c.Category.CategoryName).ToList();
 }