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))); }
public IHttpActionResult Update([FromBody] NotaFiscalViewModel notaFiscal) { try { NotaFiscal result = _notaFiscalApp.GetById(notaFiscal.Id); if (result != null) { result.Numero = notaFiscal.Numero; result.ValorTotal = notaFiscal.ValorTotal; result.Data = notaFiscal.Data; result.CNPJDestinatario = notaFiscal.CNPJDestinatario; result.CNPJEmissor = notaFiscal.CNPJEmissor; _notaFiscalApp.Update(result); } else { return(NotFound()); } return(Ok()); } catch { return(InternalServerError()); } }
public async Task <NotaFiscalViewModel> CriarNotaFiscal(NotaFiscalViewModel notaFiscalViewModel) { var notaFiscalEntity = _mapper.Map <NotaFiscalEntity>(notaFiscalViewModel); var novaNotaFiscal = await _notaFiscalService.InsertNotaFiscal(notaFiscalEntity); return(_mapper.Map <NotaFiscalViewModel>(novaNotaFiscal)); }
public NotaFiscalViewModel GetId([FromBody] NotaFiscalViewModel notaFiscal) { try { return(Mapper.Map <NotaFiscal, NotaFiscalViewModel>(_notaFiscalApp.GetById(notaFiscal.Id))); } catch { return(null); } }
public IHttpActionResult Add([FromBody] NotaFiscalViewModel notaFiscal) { try { var notaFiscalObj = Mapper.Map <NotaFiscalViewModel, NotaFiscal>(notaFiscal); notaFiscalObj.DataCadastro = System.DateTime.Now; notaFiscalObj.Ativo = true; _notaFiscalApp.Add(notaFiscalObj); return(Ok()); } catch { return(InternalServerError()); } }
public async Task <IActionResult> Delete(Guid id, NotaFiscalViewModel notaFiscal) { var commandResult = await _notaFiscalApplicationService.Remove(notaFiscal); if (commandResult.Success) { NotifyCommandResultSuccess(); return(RedirectToAction(nameof(Index))); } else { NotifyCommandResultErrors(commandResult.Errors); } return(View(notaFiscal)); }
public async Task <ActionResult <NotaFiscalViewModel> > Add(NotaFiscalViewModel notaFiscalViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var notaFiscal = _mapper.Map <NotaFiscal>(notaFiscalViewModel); notaFiscal.Cliente = await _clienteRepository.ObterPorId(notaFiscalViewModel.Cliente.ClienteId); foreach (var itemNotaFiscal in notaFiscal.ItensNotaFiscal) { itemNotaFiscal.Faixa = await _faixaRepository.ObterPorId(itemNotaFiscal.Faixa.FaixaId); } await _notaFiscalService.Adicionar(notaFiscal); return(CustomResponse(_mapper.Map <NotaFiscalViewModel>(notaFiscal))); }
public IHttpActionResult Del([FromBody] NotaFiscalViewModel notaFiscal) { try { NotaFiscal result = _notaFiscalApp.GetById(notaFiscal.Id); if (result != null) { result.Ativo = false; _notaFiscalApp.Update(result); } else { return(NotFound()); } return(Ok()); } catch { return(InternalServerError()); } }
public async Task <IActionResult> Edit(Guid id, NotaFiscalViewModel notaFiscal) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(View(notaFiscal)); } var commandResult = await _notaFiscalApplicationService.Update(notaFiscal); if (commandResult.Success) { NotifyCommandResultSuccess(); return(RedirectToAction(nameof(Index))); } else { NotifyCommandResultErrors(commandResult.Errors); } return(View(notaFiscal)); }
public void Put([FromBody] NotaFiscalViewModel notaFiscal) { _notaFiscalApp.Update(Mapper.Map <NotaFiscalViewModel, NotaFiscal>(notaFiscal)); }
public void Post([FromBody] NotaFiscalViewModel notaFiscal) { _notaFiscalApp.Add(Mapper.Map <NotaFiscalViewModel, NotaFiscal>(notaFiscal)); }
public void Put(Guid id, [FromBody] NotaFiscalViewModel notaFiscalViewModel) { _notaFiscalAppService.AtualizarNotaFiscal(id, notaFiscalViewModel); }
public async Task <IActionResult> Create([FromBody] NotaFiscalViewModel notaFiscalViewModel) { var novaNotaFiscal = await _notaFiscalAppService.CriarNotaFiscal(notaFiscalViewModel); return(Response(novaNotaFiscal)); }
public void AtualizarNotaFiscal(Guid id, NotaFiscalViewModel notaFiscalViewModel) { var notaFiscalEntity = _mapper.Map <NotaFiscalEntity>(notaFiscalViewModel); _notaFiscalService.UpdateNotaFiscal(id, notaFiscalEntity); }