コード例 #1
0
        public async Task <AlbumRatingDto> CreateAlbumRatingAsync([FromBody] AlbumRatingDto albumRatingDto)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new AlbumRatingDto();

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

                    var albumRating = await _albumRepository.CreateAlbumRatingAsync(_mapper.Map <AlbumRating>(albumRatingDto));

                    return(_mapper.Map <AlbumRatingDto>(albumRating));
                }

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