public async Task <MusicTypeDto> CreateMusicTypeAsync([FromBody] MusicTypeDto musicTypeDto) { _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType); var response = new MusicTypeDto(); if (ModelState.IsValid) { try { _logger?.LogInformation("The CreateMusicTypeAsync have been retrieved successfully."); var musicType = await _albumRepository.CreateMusicTypeAsync(_mapper.Map <MusicType>(musicTypeDto)); return(_mapper.Map <MusicTypeDto>(musicType)); } catch (Exception ex) { _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex); return(response = new MusicTypeDto { ErrorMessage = new string[] { ex.Message } }); } } else { return response = new MusicTypeDto { ErrorMessage = new string[] { "ModelState is not valid: " + ModelState.ToString() } } }; }
public async void TestCreateMusicTypeAsync() { var request = new MusicTypeDto { Name = "Classic" }; var data = await _albumsController.CreateMusicTypeAsync(request); Assert.IsAssignableFrom <MusicTypeDto>(data); bool IsValid = data.ErrorMessage == null ? true : false; Assert.True(IsValid); }
public async Task <MusicTypeDto> GetMusicTypeByIdAsync(Guid id) { _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType); var response = new MusicTypeDto(); try { _logger?.LogInformation("The GetMusicTypeByIdAsync have been retrieved successfully."); var serviceResponse = await _albumRepository.GetMusicTypeByIdAsync(id); return(_mapper.Map <MusicTypeDto>(serviceResponse)); } catch (Exception ex) { _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex); return(response = new MusicTypeDto { ErrorMessage = new string[] { ex.Message } }); } }
public Task <MusicTypeDto> CreateMusicTypeAsync(MusicTypeDto musicType) { throw new NotImplementedException(); }