public void CargarComercios()
 {
     using (var uow = UnitOfWorkProvider.BeginUnitOfWork())
     {
         var comercios = ComercioRepository.GetAll();
         gridComercios.DataSource = comercios.Select(x => new { x.Id, x.RazonSocial, x.CUIT, x.Direccion }).OrderBy(y => y.RazonSocial).ToList();
     }
 }
        public void GrabarCupon(int tarjetaId, DateTime fechaCupon,
                                int comercioId, int nroCupon, double importe,
                                int cantidadCuotas, string observaciones)
        {
            if (ExisteCupon(tarjetaId, fechaCupon, comercioId, nroCupon))
            {
                throw new Exception("El cupón ya existe");
            }

            var tarjeta = TarjetaRepository.GetById(tarjetaId);

            if (tarjeta == null)
            {
                throw new Exception("La Tarjeta es requerida");
            }

            var comercio = ComercioRepository.GetById(comercioId);

            if (comercio == null)
            {
                throw new Exception("El Comercio es requerido");
            }

            var fechaCierreTarjeta = TarjetaFechaCierreRepository.GetFechaDeCierrePorMesYAnio(tarjeta, fechaCupon.Month, fechaCupon.Year);

            if (fechaCierreTarjeta == null)
            {
                throw new Exception("La fecha de cierre de la Tarjeta es requerida");
            }

            var cuotas = CalcularCuotas(fechaCupon, importe, cantidadCuotas, tarjeta);

            // Creo la cabecera de la transaccion, o sea el cupon por el total del importe
            var transaccion = new Transaccion
            {
                Tarjeta            = tarjeta,
                Comercio           = comercio,
                FechaCompra        = fechaCupon,
                NumeroCupon        = nroCupon,
                Importe            = importe,
                CantidadCuotas     = cantidadCuotas,
                Observaciones      = observaciones,
                TarjetaFechaCierre = fechaCierreTarjeta
            };

            foreach (var cuota in cuotas)
            {
                var transaccionCuota = new TransaccionCuota
                {
                    Transaccion = transaccion,
                    NumeroCuota = cuota.NroCuota,
                    Fecha       = cuota.Fecha,
                    Importe     = cuota.Importe
                };
                TransaccionCuotaRepository.Add(transaccionCuota);
            }
        }
        public void ActualizarCupon(int cuponId, int tarjetaId, DateTime fechaCupon,
                                    int comercioId, int nroCupon, double importe,
                                    int cantidadCuotas, string observaciones)
        {
            var cupon = TraerCuponPorId(cuponId);

            if (cupon == null)
            {
                throw new Exception("Cupón inexistente");
            }

            var fechaAnterior          = cupon.FechaCompra;
            var importeAnterior        = cupon.Importe;
            var cantidadCuotasAnterior = cupon.CantidadCuotas;

            var comercio = ComercioRepository.GetById(comercioId);

            if (comercio == null)
            {
                throw new Exception("El Comercio es requerido");
            }
            cupon.Comercio = comercio;

            cupon.FechaCompra    = fechaCupon;
            cupon.NumeroCupon    = nroCupon;
            cupon.Importe        = importe;
            cupon.CantidadCuotas = cantidadCuotas;
            cupon.Observaciones  = observaciones;

            if (fechaAnterior != fechaCupon || importeAnterior != importe ||
                cantidadCuotasAnterior != cantidadCuotas)
            {
                // Acá tengo que actualizar las cuotas
                EliminarCuotasDeCupon(cupon);
                var tarjeta = TarjetaRepository.GetById(tarjetaId);
                if (tarjeta == null)
                {
                    throw new Exception("La Tarjeta es requerida");
                }
                var cuotas = CalcularCuotas(fechaCupon, importe, cantidadCuotas, tarjeta);

                foreach (var cuota in cuotas)
                {
                    var transaccionCuota = new TransaccionCuota
                    {
                        Transaccion = cupon,
                        NumeroCuota = cuota.NroCuota,
                        Fecha       = cuota.Fecha,
                        Importe     = cuota.Importe
                    };
                    TransaccionCuotaRepository.Add(transaccionCuota);
                }
            }
        }
예제 #4
0
        private void LoadComboComercios()
        {
            var comercios = ComercioRepository.GetAll().OrderBy(x => x.RazonSocial)
                            .Select(x => new ComboBoxItem {
                Text = x.RazonSocial, Value = x.Id
            }).ToList();

            cboComercios.Items.Clear();
            var list = new List <ComboBoxItem> {
                new ComboBoxItem {
                    Text = "--- Seleccione un Comercio ---", Value = -1
                }
            };

            list.AddRange(comercios);

            cboComercios.DataSource    = list;
            cboComercios.ValueMember   = "Value";
            cboComercios.DisplayMember = "Text";
        }