public async Task <IActionResult> Update(int id, GenreDtoUpdate newItem) { var result = await _genreService.UpdateGenre(id, newItem); if (result.IsSuccess == false) { return(NotFound(result)); } return(Ok(result)); }
public async Task <ServiceResponse <GenreDto> > UpdateGenre(int id, GenreDtoUpdate newItem) { var response = new ServiceResponse <GenreDto>(); Genre genre = await _context.Genres.FindAsync(id); if (genre == null) { response.IsSuccess = false; response.Message = $"id = {id} Not found."; return(response); } genre = _mapper.Map(newItem, genre); await _context.SaveChangesAsync(); GenreDto genreDTO = _mapper.Map <GenreDto>(genre); response.Data = genreDTO; return(response); }