public List <Notification> GerarNotaFiscal(PedidoViewModel pedido) { InitializeNotifications(); var notaFiscal = Mapper.Map <PedidoViewModel, NotaFiscal>(pedido); BeginTransactionQuery(); var validacaoRetorno = notaFiscal.Validar(); if (validacaoRetorno) { var notaFiscalXmlDto = Mapper.Map <NotaFiscal, NotaFiscalXmlDto>(notaFiscal); _notaFiscalService.GerarXml(notaFiscalXmlDto); } var notaFiscalRetorno = _notaFiscalService.Salvar(notaFiscal); if (notaFiscalRetorno.HasValue) { foreach (NotaFiscalItem notaFiscalItem in notaFiscal.ItensDaNotaFiscal) { notaFiscalItem.IdNotaFiscal = notaFiscalRetorno.Value; _notaFiscalItemService.Salvar(notaFiscalItem); } } CommitQuery(); return(GetNotifications()); }