Example #1
0
        public override bool Delete(long id)
        {
            var venda  = Get(id);
            var loteBo = new LoteLogic();
            var lote   = loteBo.Get(venda.LoteId);

            lote.Comprado = false;

            loteBo.Save(lote);

            return(base.Delete(id));
        }
Example #2
0
        protected override void Insert(Venda entity)
        {
            if (entity.DiaVencimento == 0)
            {
                throw new Exception("O dia de vencimento deve ser informada corretamente.");
            }

            using (var scope = new TransactionScope())
            {
                var loteBo       = new LoteLogic();
                var loteamentoBo = new LoteamentoLogic();
                var lote         = loteBo.Get(entity.LoteId);

                if (lote.Comprado)
                {
                    throw new Exception("O lote selecionado foi comprado por outra pessoa enquanto você concluía sua aquisição.\nPor favor, selecione outro lote.");
                }

                lote.Comprado = true;
                loteBo.Save(lote);

                if (lote.LoteamentoId != null)
                {
                    lote.Loteamento = loteamentoBo.Get((long)lote.LoteamentoId);
                }

                if (entity.QuantParcelas < 1 || entity.QuantParcelas > lote.Loteamento.QuantParcelas)
                {
                    throw new Exception($"A quantidade de parcelas deve estar entre 1 e {lote.Loteamento.QuantParcelas}.");
                }

                entity.Valor        = lote.Valor;
                entity.ValorParcela = entity.Valor / entity.QuantParcelas;
                entity.DataHora     = DateTime.Now;

                base.Insert(entity);

                var tituloBo = new TituloLogic();
                tituloBo.GerarTitulos(entity.Id);

                scope.Complete();
            }
        }