public async Task <ActionResult <NotaFiscalViewModel> > Update(int id, NotaFiscalViewModel notaFiscalViewModel) { if (id != notaFiscalViewModel.NotaFiscalId) { NotifyError("O id informado não é o mesmo que foi informado na query"); return(CustomResponse(notaFiscalViewModel)); } if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var notaFiscal = _mapper.Map <NotaFiscal>(notaFiscalViewModel); notaFiscal.Cliente = await _clienteRepository.ObterPorId(notaFiscalViewModel.Cliente.ClienteId); await _itemNotaFiscalRepository.RemoverPorNotaFiscalId(notaFiscal.NotaFiscalId); foreach (var itemNotaFiscal in notaFiscal.ItensNotaFiscal) { itemNotaFiscal.ItemNotaFiscalId = 0; if (itemNotaFiscal.Faixa?.FaixaId > 0) { itemNotaFiscal.Faixa = await _faixaRepository.ObterPorId(itemNotaFiscal.Faixa.FaixaId); } } await _notaFiscalService.Atualizar(notaFiscal); return(CustomResponse(_mapper.Map <NotaFiscalViewModel>(notaFiscal))); }