//TABELAS DE VALOR /*********************************************************************************/ public TabelaValor SalvarTabelaDeValor(TabelaValor tabela, IList <TabelaValorItem> itens) { using (ISession sessao = ObterSessao()) { using (ITransaction tran = sessao.BeginTransaction()) { tabela.Contrato = sessao.Get <ContratoADM>(tabela.Contrato.ID); sessao.SaveOrUpdate(tabela); if (itens != null && itens.Count > 0) { foreach (var item in itens) { item.Tabela = tabela; item.Plano = sessao.Get <Plano>(item.Plano.ID); sessao.SaveOrUpdate(item); } } tran.Commit(); } } return(tabela); }
public void Duplicar(Object tabelaValorID, DateTime inicio, DateTime fim, Taxa taxa) { IList <Plano> planos = Plano.CarregaPlanosDaTabelaDeValor(tabelaValorID); PersistenceManager pm = new PersistenceManager(); pm.BeginTransactionContext(); try { TabelaValor tabela = new TabelaValor(tabelaValorID); pm.Load(tabela); TabelaValor novaTabela = new TabelaValor(); novaTabela.ContratoID = tabela.ContratoID; novaTabela.Inicio = inicio; novaTabela.Fim = fim; pm.Save(novaTabela); taxa.TabelaValorID = novaTabela.ID; pm.Save(taxa); if (planos != null) //se tem planos, duplica os itens de tabela de valor para cada plano, aplicando a nova taxa { foreach (Plano plano in planos) { IList <TabelaValorItem> itens = TabelaValorItem.CarregarPorTabela(tabela.ID, plano.ID, pm); if (itens == null || itens.Count == 0) { continue; } foreach (TabelaValorItem item in itens) { item.ID = null; item.TabelaID = novaTabela.ID; item.AplicaTaxa(taxa, true); pm.Save(item); } } } pm.Commit(); } catch (Exception ex) { pm.Rollback(); throw ex; } finally { pm = null; } }
public void RecalcularTaxaEmPlanos(Object tabelaValorID, Taxa taxa) { IList <Plano> planos = Plano.CarregaPlanosDaTabelaDeValor(tabelaValorID); if (planos == null) { return; } PersistenceManager pm = new PersistenceManager(); pm.BeginTransactionContext(); try { TabelaValor tabela = new TabelaValor(tabelaValorID); pm.Load(tabela); foreach (Plano plano in planos) { IList <TabelaValorItem> itens = TabelaValorItem.CarregarPorTabela(tabela.ID, plano.ID, pm); if (itens == null || itens.Count == 0) { continue; } foreach (TabelaValorItem item in itens) { item.AplicaTaxa(taxa, false); pm.Save(item); } } pm.Commit(); } catch (Exception ex) { pm.Rollback(); throw ex; } finally { pm = null; } }
public TabelaValor CarregarTabela(long id, long?contratanteId = null) { TabelaValor ret = null; using (ISession sessao = ObterSessao()) { ret = sessao.Query <TabelaValor>() .Fetch(c => c.Contrato) .Where(c => c.ID == id).SingleOrDefault(); if (contratanteId.HasValue && contratanteId.Value > 0) { var operadora = sessao.Query <Operadora>() .Where(o => o.ID == ret.Contrato.Operadora.ID && o.ContratanteId == contratanteId.Value).SingleOrDefault(); if (operadora == null) { throw new ApplicationException("Security exception."); } } } return(ret); }