コード例 #1
0
        public async Task <IActionResult> Adicionar(AlbumViewModel albumViewModel)
        {
            await _albumService.Adicionar(_mapper.Map <Album>(albumViewModel));

            await Commit(_albumRepository);

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

            return(CreatedAtRoute("AlbumPorId", new { id = albumViewModel.Id }, albumViewModel));
        }
コード例 #2
0
        public async Task <ActionResult <AlbumViewModel> > Add(AlbumViewModel albumViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var album = _mapper.Map <Album>(albumViewModel);

            album.Artista = await _artistaRepository.ObterPorId(album.Artista.ArtistaId);

            await _albumService.Adicionar(album);

            return(CustomResponse(albumViewModel));
        }
コード例 #3
0
        public async Task <IActionResult> Cadastrar(AlbumViewModel albumViewModel)
        {
            if (!ModelState.IsValid)
            {
                await PopularSelectList(albumViewModel);

                return(View(albumViewModel));
            }

            var albumResponse = await _albumService.Adicionar(albumViewModel);

            if (ResponsePossuiErros(albumResponse.ResponseResult))
            {
                await PopularSelectList(albumViewModel);

                return(View(albumResponse));
            }

            return(RedirectToAction("Index"));
        }