public JsonResult SalvarAgendamentoDeDescarregamento(AgendamentoDeDescarregamentoSalvarVm agendamentoDeDescarregamentoSalvarVm) { try { QuotaPesoVm quotaPesoVm = _agendamentoDeCargaService.SalvarAgendamentoDeDescarregamento(agendamentoDeDescarregamentoSalvarVm); return(Json(new { Sucesso = true, Quota = quotaPesoVm })); } catch (Exception ex) { return(Json(new { Sucesso = false, Mensagem = ex.Message })); } }
public void ConsigoConsultarUmAgendamentoPeloNumeroDaNotaFiscal() { Quota quota = DefaultObjects.ObtemQuotaDeDescarregamento(); //AgendamentoDeDescarregamento agendamento = DefaultObjects.ObtemAgendamentoDeDescarregamento(quota); var agendamentoVm = new AgendamentoDeDescarregamentoSalvarVm { IdQuota = quota.Id, Placa = "IOQ5338", IdAgendamento = 0, NotasFiscais = new List <NotaFiscalVm> { new NotaFiscalVm { Numero = "1234", Serie = "1", DataDeEmissao = DateTime.Today.ToShortDateString(), CnpjDoEmitente = "123", NomeDoEmitente = "Emitente", CnpjDoContratante = "666", NomeDoContratante = "contratante", NumeroDoContrato = "4001", Peso = 100, Valor = 150 } } }; quota.InformarAgendamento(agendamentoVm); DefaultPersistedObjects.PersistirQuota(quota); var consultaQuota = ObjectFactory.GetInstance <IConsultaQuota>(); UnitOfWorkNh.Session.Clear(); var filtro = new ConferenciaDeCargaFiltroVm { CodigoTerminal = "1000", NumeroNf = "1234"/*, * CodigoRealizacaoDeAgendamento = (int) Enumeradores.RealizacaoDeAgendamento.NaoRealizado*/ }; KendoGridVm kendoGridVm = consultaQuota.Consultar(new PaginacaoVm { Page = 1, PageSize = 10, Take = 10 }, filtro); Assert.AreEqual(1, kendoGridVm.QuantidadeDeRegistros); }
public QuotaPesoVm SalvarAgendamentoDeDescarregamento(AgendamentoDeDescarregamentoSalvarVm agendamentoDeDescarregamentoSalvarVm) { try { _unitOfWork.BeginTransaction(); Quota quota = _quotas.BuscaPorId(agendamentoDeDescarregamentoSalvarVm.IdQuota); quota.InformarAgendamento(agendamentoDeDescarregamentoSalvarVm); _quotas.Save(quota); _unitOfWork.Commit(); return(_builderQuotaPeso.BuildSingle(quota)); } catch (Exception) { _unitOfWork.RollBack(); throw; } }
public virtual void Atualizar(AgendamentoDeDescarregamentoSalvarVm agendamentoDeDescarregamentoCadastroVm) { VerificaSePodeAlterarAgendamento(); Placa = agendamentoDeDescarregamentoCadastroVm.Placa; IList <NotaFiscal> notasParaRemover = NotasFiscais.Where(nfSalva => agendamentoDeDescarregamentoCadastroVm.NotasFiscais .All(nfCadastro => nfCadastro.Numero != nfSalva.Numero || nfCadastro.Serie != nfSalva.Serie || nfCadastro.CnpjDoEmitente != nfSalva.CnpjDoEmitente)).ToList(); foreach (var notaFiscal in notasParaRemover) { NotasFiscais.Remove(notaFiscal); } var query = (from nfSalva in NotasFiscais join nfCadastro in agendamentoDeDescarregamentoCadastroVm.NotasFiscais on new { nfSalva.Numero, nfSalva.Serie, nfSalva.CnpjDoEmitente } equals new { nfCadastro.Numero, nfCadastro.Serie, nfCadastro.CnpjDoEmitente } select new { nfSalva, nfCadastro } ); foreach (var registro in query) { registro.nfSalva.Alterar(registro.nfCadastro); } IList <NotaFiscalVm> notasParaAdicionar = agendamentoDeDescarregamentoCadastroVm.NotasFiscais.Where(nfCadastro => NotasFiscais .All(nfSalva => nfCadastro.Numero != nfSalva.Numero || nfCadastro.Serie != nfSalva.Serie || nfCadastro.CnpjDoEmitente != nfSalva.CnpjDoEmitente)).ToList(); foreach (var notaFiscalVm in notasParaAdicionar) { AdicionarNotaFiscal(notaFiscalVm); } if (NotasFiscais.Count == 0) { throw new AgendamentoDeDescarregamentoSemNotaFiscalException(); } CalculaPesoTotal(); }
public virtual AgendamentoDeDescarregamento InformarAgendamento(AgendamentoDeDescarregamentoSalvarVm agendamentoDeDescarregamentoSalvarVm) { AgendamentoDeDescarregamento agendamento; if (agendamentoDeDescarregamentoSalvarVm.IdAgendamento == 0) { var factory = new AgendamentoDeDescarregamentoFactory(); foreach (var notaFiscal in agendamentoDeDescarregamentoSalvarVm.NotasFiscais) { factory.AdicionarNotaFiscal(notaFiscal); } agendamento = (AgendamentoDeDescarregamento)factory.Construir(this, agendamentoDeDescarregamentoSalvarVm.Placa); Agendamentos.Add(agendamento); } else { agendamento = (AgendamentoDeDescarregamento)Agendamentos.Single(x => x.Id == agendamentoDeDescarregamentoSalvarVm.IdAgendamento); agendamento.Atualizar(agendamentoDeDescarregamentoSalvarVm); } VerificaSeExisteApenasUmAgendamentoParaCadaPlaca(); CalculaPesoAgendado(); return(agendamento); }