public ActionResult <GenreApiModel> Put(int id, [FromBody] GenreApiModel input) { try { if (input == null) { return(BadRequest()); } if (_chinookSupervisor.GetGenreById(id) == null) { return(NotFound()); } // var errors = JsonConvert.SerializeObject(ModelState.Values // .SelectMany(state => state.Errors) // .Select(error => error.ErrorMessage)); // Debug.WriteLine(errors); if (_chinookSupervisor.UpdateGenre(input)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <ActionResult <GenreApiModel> > Put(int id, [FromBody] GenreApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } if (await _chinookSupervisor.GetGenreByIdAsync(id, ct) == null) { return(NotFound()); } var errors = JsonConvert.SerializeObject(ModelState.Values .SelectMany(state => state.Errors) .Select(error => error.ErrorMessage)); Debug.WriteLine(errors); if (await _chinookSupervisor.UpdateGenreAsync(input, ct)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public GenreApiModel AddGenre(GenreApiModel newGenreApiModel) { var genre = newGenreApiModel.Convert(); genre = _genreRepository.Add(genre); newGenreApiModel.GenreId = genre.GenreId; return(newGenreApiModel); }
public async Task <GenreApiModel> AddGenreAsync(GenreApiModel newGenreApiModel, CancellationToken ct = default) { var genre = newGenreApiModel.Convert; genre = await _genreRepository.AddAsync(genre, ct); newGenreApiModel.GenreId = genre.GenreId; return(newGenreApiModel); }
public bool UpdateGenre(GenreApiModel genreApiModel) { var genre = _genreRepository.GetById(genreApiModel.GenreId); if (genre == null) { return(false); } genre.GenreId = genreApiModel.GenreId; genre.Name = genreApiModel.Name; return(_genreRepository.Update(genre)); }
public async Task <bool> UpdateGenreAsync(GenreApiModel genreApiModel, CancellationToken ct = default) { var genre = await _genreRepository.GetByIdAsync(genreApiModel.GenreId, ct); if (genre == null) { return(false); } genre.GenreId = genreApiModel.GenreId; genre.Name = genreApiModel.Name; return(await _genreRepository.UpdateAsync(genre, ct)); }
public ActionResult <GenreApiModel> Post([FromBody] GenreApiModel input) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, _chinookSupervisor.AddGenre(input))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <ActionResult <GenreApiModel> > Post([FromBody] GenreApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, await _chinookSupervisor.AddGenreAsync(input, ct))); } catch (Exception ex) { return(StatusCode(500, ex)); } }