コード例 #1
0
ファイル: OperadoraFacade.cs プロジェクト: matheussi/cadben
        public TabelaValorItem CarregarTabelaValorItem(long id, long?contratanteId = null)
        {
            TabelaValorItem ret = null;

            using (ISession sessao = ObterSessao())
            {
                ret = sessao.Query <TabelaValorItem>()
                      .Fetch(i => i.Tabela)
                      .ThenFetch(t => t.Contrato)
                      .Where(i => i.ID == id).SingleOrDefault();

                if (contratanteId.HasValue && contratanteId.Value > 0)
                {
                    var operadora = sessao.Query <Operadora>()
                                    .Where(o => o.ID == ret.Tabela.Contrato.Operadora.ID && o.ContratanteId == contratanteId.Value).SingleOrDefault();

                    if (operadora == null)
                    {
                        throw new ApplicationException("Security exception.");
                    }
                }
            }

            return(ret);
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
ファイル: OperadoraFacade.cs プロジェクト: matheussi/cadben
        /********/

        public TabelaValorItem SalvarTabelaValorItem(TabelaValorItem item)
        {
            using (ISession sessao = ObterSessao())
            {
                using (ITransaction tran = sessao.BeginTransaction())
                {
                    sessao.SaveOrUpdate(item);
                    tran.Commit();
                }
            }

            return(item);
        }
コード例 #4
0
        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;
            }
        }