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

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

                    var ratingType = await _albumRepository.CreateRatingTypeAsync(_mapper.Map <RatingType>(ratingTypeDto));

                    return(_mapper.Map <RatingTypeDto>(ratingType));
                }

                catch (Exception ex)
                {
                    _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex);
                    return(response = new RatingTypeDto {
                        ErrorMessage = new string[] { ex.Message }
                    });
                }
            }
            else
            {
                return response = new RatingTypeDto {
                           ErrorMessage = new string[] { "ModelState is not valid: " + ModelState.ToString() }
                }
            };
        }
        public async void TestCreateRatingTypeAsync()
        {
            var request = new RatingTypeDto
            {
                Name  = "Star 6",
                Value = 6
            };

            var data = await _albumsController.CreateRatingTypeAsync(request);

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

            Assert.True(IsValid);
        }
Example #3
0
        public async Task <RatingTypeDto> GetRatingTypeByIdAsync(Guid id)
        {
            _logger?.LogDebug("'{0}' has been invoked", MethodBase.GetCurrentMethod().DeclaringType);
            var response = new RatingTypeDto();

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

                var serviceResponse = await _albumRepository.GetRatingTypeByIdAsync(id);

                return(_mapper.Map <RatingTypeDto>(serviceResponse));
            }
            catch (Exception ex)
            {
                _logger?.LogCritical("There was an error on '{0}' invocation: {1}", MethodBase.GetCurrentMethod().DeclaringType, ex);
                return(response = new RatingTypeDto {
                    ErrorMessage = new string[] { ex.Message }
                });
            }
        }
 public Task <RatingTypeDto> CreateRatingTypeAsync(RatingTypeDto ratingType)
 {
     throw new NotImplementedException();
 }