Exemplo n.º 1
0
        public async Task <ArtistDTO> PatchAsync(ArtistUpdateDTO artist)
        {
            this.Logger.LogTrace("PutAsync called");

            var result = await this.ArtistUpdateService.UpdateAsync(this.Mapper.Map <ArtistUpdateModel>(artist));

            return(this.Mapper.Map <ArtistDTO>(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update(int id, [FromBody] ArtistUpdateDTO artistDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Update Attempted on record with id: {id} ");
                if (id < 1 || artistDTO == null || id != artistDTO.ArtistId)
                {
                    _logger.LogWarn($"{location}: Update failed with bad data - id: {id}");
                    return(BadRequest());
                }
                var isExists = await _artistRepository.isExists(id);

                if (!isExists)
                {
                    _logger.LogWarn($"{location}: Failed to retrieve record with id: {id}");
                    return(NotFound());
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"{location}: Data was Incomplete");
                    return(BadRequest(ModelState));
                }
                var artist    = _mapper.Map <Artist>(artistDTO);
                var isSuccess = await _artistRepository.Update(artist);

                if (!isSuccess)
                {
                    return(InternalError($"{location}: Update failed for record with id: {id}"));
                }
                _logger.LogInfo($"{location}: Record with id: {id} successfully updated");
                return(NoContent());
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }