Exemplo n.º 1
0
        public async Task <IActionResult> Adicionar(MusicaViewModel musicaViewModel)
        {
            await _musicaService.Adicionar(_mapper.Map <Musica>(musicaViewModel));

            await Commit(_musicaRepository);

            if (!OperacaoValida())
            {
                return(CustomBadRequest());
            }

            return(CreatedAtRoute("MusicaPorId", new { id = musicaViewModel.Id }, musicaViewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Cadastrar(MusicaViewModel musicaViewModel)
        {
            if (!ModelState.IsValid)
            {
                await PopularSelectList(musicaViewModel);

                return(View(musicaViewModel));
            }

            var musicaResponse = await _musicaService.Adicionar(musicaViewModel);

            if (ResponsePossuiErros(musicaResponse.ResponseResult))
            {
                await PopularSelectList(musicaResponse);

                return(View(musicaResponse));
            }

            return(RedirectToAction("Index"));
        }