public async Task <IActionResult> Put([FromBody] Product product,
                                              [FromHeader(Name = "x-correlationToken")]
                                              string correlationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var isSuccessful = true;
            var errorMessage = string.Empty;

            Guard.ForNullOrEmpty(correlationToken, "correlationToken");
            Guard.ForNullObject(product, "Product parameter missing in catalog put");
            Guard.ForLessEqualZero(product.Id, "album.Id is zerp in catalog put");

            try
            {
                await _catalogBusinessServices.Update(correlationToken, product);
            }
            catch (Exception ex)
            {
                errorMessage = $"Catalog: Exception on Put operation:{ex.Message} for Request{correlationToken}";
                _logger.LogError(errorMessage);
                isSuccessful = false;
            }

            if (!isSuccessful)
            {
                return(BadRequest(errorMessage));
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> Put([FromBody] MusicUpdateDto musicUpdateDto, string correlationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Guard.ForNullOrEmpty(correlationToken, "correlationToken");
            Guard.ForNullObject(musicUpdateDto, "Album");
            Guard.ForLessEqualZero(musicUpdateDto.Id, "album.Id");

            var updatedAlbum = Mapper.MapDtoToProduct(musicUpdateDto);

            updatedAlbum = await _catalogBusinessServices.Update(correlationToken, updatedAlbum);

            var album = Mapper.MapToMusicDto(updatedAlbum);

            return(Ok(album));
        }