Example #1
0
        public async Task <ArtistDto> CreateArtistAsync([FromBody] ArtistDto artistDto)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new ArtistDto();

            if (ModelState.IsValid)
            {
                try
                {
                    _logger?.LogInformation("The CreateArtistAsync have been retrieved successfully.");

                    var artist = await _albumRepository.CreateArtistAsync(_mapper.Map <Artist>(artistDto));

                    return(_mapper.Map <ArtistDto>(artist));
                }

                catch (Exception ex)
                {
                    _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex);
                    return(response = new ArtistDto {
                        ErrorMessage = new string[] { ex.Message }
                    });
                }
            }
            else
            {
                return response = new ArtistDto {
                           ErrorMessage = new string[] { "ModelState is not valid: " + ModelState.ToString() }
                }
            };
        }