コード例 #1
0
        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() }
                }
            };
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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 }
                });
            }
        }
コード例 #4
0
 public Task <MusicTypeDto> CreateMusicTypeAsync(MusicTypeDto musicType)
 {
     throw new NotImplementedException();
 }