public ActionResult <TrackApiModel> Put([FromRoute] int id, [FromBody] TrackApiModel input) { try { if (input == null) { return(BadRequest()); } if (_chinookSupervisor.GetTrackById(id) == null) { return(NotFound()); } // var errors = JsonConvert.SerializeObject(ModelState.Values // .SelectMany(state => state.Errors) // .Select(error => error.ErrorMessage)); // Debug.WriteLine(errors); if (_chinookSupervisor.UpdateTrack(input)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <ActionResult <TrackApiModel> > Put(int id, [FromBody] TrackApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } if (await _chinookSupervisor.GetTrackByIdAsync(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.UpdateTrackAsync(input, ct)) { return(Ok(input)); } return(StatusCode(500)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public TrackApiModel AddTrack(TrackApiModel newTrackApiModel) { var track = newTrackApiModel.Convert(); _trackRepository.Add(track); newTrackApiModel.TrackId = track.TrackId; return(newTrackApiModel); }
public ActionResult <TrackApiModel> Post([FromBody] TrackApiModel input) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, _chinookSupervisor.AddTrack(input))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <ActionResult <TrackApiModel> > Post([FromBody] TrackApiModel input, CancellationToken ct = default) { try { if (input == null) { return(BadRequest()); } return(StatusCode(201, await _chinookSupervisor.AddTrackAsync(input, ct))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public bool UpdateTrack(TrackApiModel trackApiModel) { var track = _trackRepository.GetById(trackApiModel.TrackId); if (track == null) { return(false); } track.TrackId = trackApiModel.TrackId; track.Name = trackApiModel.Name; track.AlbumId = trackApiModel.AlbumId; track.MediaTypeId = trackApiModel.MediaTypeId; track.GenreId = trackApiModel.GenreId; track.Composer = trackApiModel.Composer; track.Milliseconds = trackApiModel.Milliseconds; track.Bytes = trackApiModel.Bytes; track.UnitPrice = trackApiModel.UnitPrice; return(_trackRepository.Update(track)); }
public async Task <bool> UpdateTrackAsync(TrackApiModel trackViewModel, CancellationToken ct = default) { var track = await _trackRepository.GetByIdAsync(trackViewModel.TrackId, ct); if (track == null) { return(false); } track.TrackId = trackViewModel.TrackId; track.Name = trackViewModel.Name; track.AlbumId = trackViewModel.AlbumId; track.MediaTypeId = trackViewModel.MediaTypeId; track.GenreId = trackViewModel.GenreId; track.Composer = trackViewModel.Composer; track.Milliseconds = trackViewModel.Milliseconds; track.Bytes = trackViewModel.Bytes; track.UnitPrice = trackViewModel.UnitPrice; return(await _trackRepository.UpdateAsync(track, ct)); }
public async Task <TrackApiModel> AddTrackAsync(TrackApiModel newTrackViewModel, CancellationToken ct = default) { var track = new Track { TrackId = newTrackViewModel.TrackId, Name = newTrackViewModel.Name, AlbumId = newTrackViewModel.AlbumId, MediaTypeId = newTrackViewModel.MediaTypeId, GenreId = newTrackViewModel.GenreId, Composer = newTrackViewModel.Composer, Milliseconds = newTrackViewModel.Milliseconds, Bytes = newTrackViewModel.Bytes, UnitPrice = newTrackViewModel.UnitPrice }; await _trackRepository.AddAsync(track, ct); newTrackViewModel.TrackId = track.TrackId; return(newTrackViewModel); }
public async Task <TrackApiModel> AddTrackAsync(TrackApiModel newTrackViewModel, CancellationToken ct = default) { /*var track = new Track * { * TrackId = newTrackViewModel.TrackId, * Name = newTrackViewModel.Name, * AlbumId = newTrackViewModel.AlbumId, * MediaTypeId = newTrackViewModel.MediaTypeId, * GenreId = newTrackViewModel.GenreId, * Composer = newTrackViewModel.Composer, * Milliseconds = newTrackViewModel.Milliseconds, * Bytes = newTrackViewModel.Bytes, * UnitPrice = newTrackViewModel.UnitPrice * };*/ var track = newTrackViewModel.Convert; await _trackRepository.AddAsync(track, ct); newTrackViewModel.TrackId = track.TrackId; return(newTrackViewModel); }