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)); }
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)); }
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")); }