Example #1
0
        public async Task <ArtistResponse> GetArtistAsync(GetArtistRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            Artist result = await _artistRespository.GetAsync(request.Id);

            return(result == null ? null : _artistMapper.Map(result));
        }
Example #2
0
        public async Task <ItemResponse> EditItemAsync(EditItemRequest request)
        {
            Item existingRecord = await _itemRespository.GetAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            Genre existingGenre = await _genreRespository.GetAsync(request.GenreId);

            if (existingGenre == null)
            {
                throw new NotFoundException($"Genre with {request.GenreId} is not present");
            }

            Artist existingArtist = await _artistRespository.GetAsync(request.ArtistId);

            if (existingArtist == null)
            {
                throw new NotFoundException($"Artist with {request.ArtistId} is not present");
            }

            Item entity = _itemMapper.Map(request);
            Item result = _itemRespository.Update(entity);

            int modifiedRecords = await _itemRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);
            _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id);

            return(_itemMapper.Map(result));
        }