示例#1
0
        public async Task <SongDto> CreateSongAsync([FromBody] SongDto songDto)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new SongDto();

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

                    var song = await _albumRepository.CreateSongAsync(_mapper.Map <Song>(songDto));

                    return(_mapper.Map <SongDto>(song));
                }

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