예제 #1
0
        public IActionResult Post(int idAlbum, [FromBody] Models.Request.MusicaDto musicaRequest)
        {
            if (albumRepository.Obter(idAlbum) == null)
            {
                return(NotFound());
            }

            var musica    = MapearDtoParaDominio(musicaRequest);
            var mensagens = musicaService.Validar(musica);

            if (mensagens.Count > 0)
            {
                return(BadRequest(mensagens));
            }

            musicaRepository.SalvarMusica(idAlbum, musica);
            return(CreatedAtRoute("GetMusica", new { idAlbum = idAlbum, id = musica.Id }, musica));
        }
        public IActionResult Post(int idAlbum, [FromBody] Models.Request.MusicaDto musicaRequest)
        {
            var album = albumRepository.Obter(idAlbum);

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

            var musica = new Musica(musicaRequest.Nome, musicaRequest.Duracao, album);

            var mensagens = musicaService.Validar(musica);

            if (mensagens.Count > 0)
            {
                return(BadRequest(mensagens));
            }

            var musicaCadastrada = musicaRepository.SalvarMusica(idAlbum, musica);

            contexto.SaveChanges();

            return(CreatedAtRoute("GetMusica", new { id = musicaCadastrada.IdMusica }, musicaCadastrada));
        }