Exemple #1
0
        public async Task <IActionResult> Update(int id, [FromBody] GenreUpdateDTO genreDTO)
        {
            var location = GetControllerActionNames();

            try
            {
                _logger.LogInfo($"{location}: Started update genre");
                if (id < 1 || genreDTO == null || id != genreDTO.Id)
                {
                    _logger.LogError($"{location}: Empty request");
                    return(BadRequest());
                }
                var isExists = await _genreRepository.IsExists(id);

                if (!isExists)
                {
                    _logger.LogError($"{location}: Wrong Id");
                    return(BadRequest());
                }
                var author    = _mapper.Map <Genre>(genreDTO);
                var isSuccess = await _genreRepository.Update(author);

                if (!isSuccess)
                {
                    return(InternalError("Genre update failed"));
                }
                _logger.LogInfo("Genre updated");
                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{location} : Something wrong {ex.Message}"));
            }
        }
        public async Task <GenreDTO> PatchAsync(GenreUpdateDTO genre)
        {
            this.Logger.LogTrace($"{nameof(this.PutAsync)} called");

            var result = await this.GenreUpdateService.UpdateAsync(this.Mapper.Map <GenreUpdateModel>(genre));

            return(this.Mapper.Map <GenreDTO>(result));
        }
        public IActionResult UpdateGenre([FromBody] GenreUpdateDTO genre, Guid genreID)
        {
            try
            {
                genreService.UpdateGenre(genre, genreID);

                return(NoContent());
            }
            catch
            {
                return(NotFound());
            }
        }
 public void UpdateGenre(GenreUpdateDTO genre, Guid genreID)
 {
     genreRepository.UpdateGenre(mapper.Map <Genre>(genre), genreID);
 }