Example #1
0
        public async Task <ActionResult <MusicDTO> > CreateMusic([FromBody] SaveMusicDTO saveMusicDTO)
        {
            var validator       = new SaveMusicDTOValidator();
            var validatorResult = await validator.ValidateAsync(saveMusicDTO);

            if (!validatorResult.IsValid)
            {
                return(BadRequest(validatorResult.Errors));
            }

            var musicDTO = await _musicService.CreateMusic(saveMusicDTO);

            return(Ok(musicDTO));
        }
Example #2
0
        public async Task <ActionResult <MusicDTO> > UpdateMusic(int id, [FromBody] SaveMusicDTO saveMusicDTO)
        {
            var validator       = new SaveMusicDTOValidator();
            var validatorResult = await validator.ValidateAsync(saveMusicDTO);

            var requestIsInvalid = id == 0 || !validatorResult.IsValid;

            if (requestIsInvalid)
            {
                return(BadRequest(validatorResult.Errors));
            }

            var musicToBeUpdate = await _musicService.GetMusicById(id);

            if (musicToBeUpdate == null)
            {
                return(NotFound());
            }
            var updatedMusicDTO = await _musicService.UpdateMusic(musicToBeUpdate, saveMusicDTO);

            return(Ok(updatedMusicDTO));
        }