コード例 #1
0
        public IActionResult UpdateSong(Guid songId, [FromBody] SongForUpdate songForUpdate)
        {
            if (songForUpdate == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var song = _sprotifyRepository.GetSong(songId);

            if (song == null)
            {
                return(NotFound());
            }

            Mapper.Map(songForUpdate, song);

            _sprotifyRepository.UpdateSong(song);

            if (!_sprotifyRepository.Save())
            {
                throw new Exception($"Updating song {songId} failed.");
            }

            return(NoContent());
        }