public async Task <AlbumDto> CreateAlbumAsync([FromBody] AlbumDto albumDto) { _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType); var response = new AlbumDto(); if (ModelState.IsValid) { try { _logger?.LogInformation("The CreateAlbumAsync have been retrieved successfully."); var album = await _albumRepository.CreateAlbumAsync(_mapper.Map <Album>(albumDto)); return(_mapper.Map <AlbumDto>(album)); } catch (Exception ex) { _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex); return(response = new AlbumDto { ErrorMessage = new string[] { ex.Message } }); } } else { return response = new AlbumDto { ErrorMessage = new string[] { "ModelState is not valid: " + ModelState.ToString() } } }; }
public async Task <AlbumDto> CreateAlbumAsync(AlbumDto album) { _logger?.LogInformation("{0} has been retrieved successfully.", MethodBase.GetCurrentMethod().Name); var repoResponse = await _repository.CreateAlbumAsync(_mapper.Map <AlbumEntity>(album)); var response = _mapper.Map <AlbumDto>(repoResponse); return(response); }
public async Task <IAlbum> CreateAlbumAsync(int artistId, string name) { var data = await _albumRepository.CreateAlbumAsync(new NewAlbumDataDto { ArtistId = artistId, Name = name, }); return(data != null?_dependencyMapper.Construct <Album>(data) : null); }