Ejemplo n.º 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() }
                }
            };
        }
        public async void TestCreateAlbumRatingAsync()
        {
            var request = new AlbumRatingDto
            {
                AlbumId      = Guid.Parse("0f078d0e-6602-4375-a088-ab8d00facdd1"),
                RatingTypeId = Guid.Parse("5befa4aa-06fd-4390-a2f5-a54600d4e3b3")
            };

            var data = await _albumsController.CreateAlbumRatingAsync(request);

            Assert.IsAssignableFrom <AlbumRatingDto>(data);
            bool IsValid = data.ErrorMessage == null ? true : false;

            Assert.True(IsValid);
        }
Ejemplo n.º 3
0
        public async Task <AlbumRatingDto> GetAlbumRatingByIdAsync(Guid id)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new AlbumRatingDto();

            try
            {
                _logger?.LogInformation("The GetAlbumRatingByIdAsync have been retrieved successfully.");

                var serviceResponse = await _albumRepository.GetAlbumRatingByIdAsync(id);

                return(_mapper.Map <AlbumRatingDto>(serviceResponse));
            }
            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 }
                });
            }
        }
 public Task <AlbumRatingDto> CreateAlbumRatingAsync(AlbumRatingDto albumRating)
 {
     throw new NotImplementedException();
 }