Exemple #1
0
        public IActionResult CrearProducto(int?id)
        {
            if (id != null)
            {
                RegistrosProductosViewModels pdt0 = new RegistrosProductosViewModels();
                pdt0.IdUsuario = Convert.ToInt32(id);
                return(View(pdt0));
            }

            return(RedirectToAction("AdministrarUsuario", "Administrador"));
        }
Exemple #2
0
        public async Task <IActionResult> CrearProducto(RegistrosProductosViewModels pdt)
        {
            int?id = pdt.IdUsuario;


            GestionProductoUsuario Validar = new GestionProductoUsuario(_userManager, _signinManager, _context, _mapper, _usuarioRepository, _repositoryPrestamos, _cuentaRepository, _tarjetaCreditoRepository);
            var validacion = await Validar.ValidarProducto(pdt);

            if (validacion == null)
            {
                return(RedirectToAction("Producto", "Usuario", new { @id = id }));
            }

            return(View(validacion));
        }
Exemple #3
0
        public async Task <RegistrosProductosViewModels> ValidarProducto(RegistrosProductosViewModels pdt)
        {
            int?id = pdt.IdUsuario;

            try
            {
                if (pdt.TipoCuenta == "Ahorro")
                {
                    if (pdt.Balance == null)
                    {
                        //pdt.Balance = 0;
                        ModelState.AddModelError("", "La cantidad insertada debe contener menos de 13 digitos, intentelo de nuevo");
                        return(pdt);
                    }

                    if (pdt.Balance < 0)
                    {
                        ModelState.AddModelError("", "La cantidad no pueder ser negativa.");
                        return(pdt);
                    }

A:
                    Random r = new Random();
                    int codigo = r.Next(100000000, 999999999);

                    if (!ValidarCodigo(codigo))
                    {
                        goto A;
                    }
                    pdt.NumeroCuenta = codigo;

                    var newCuenta = _mapper.Map <Cuenta>(pdt);
                    await _cuentaRepository.AddAsync(newCuenta);

                    return(null);
                }
                else if (pdt.TipoCuenta == "Credito")
                {
                    DateTime fecha           = DateTime.Now;
                    DateTime Pago            = Convert.ToDateTime(fecha);
                    DateTime FechaExpiracion = Convert.ToDateTime(fecha);
                    Pago            = Pago.AddDays(20);
                    FechaExpiracion = FechaExpiracion.AddDays(30);

                    if (pdt.MontoLimite == null)
                    {
                        //  pdt.MontoLimite = 0;
                        ModelState.AddModelError("", "Necesita Ingresar el monto limite de esta tarjeta");
                        return(pdt);
                    }

                    if (pdt.MontoLimite < 0)
                    {
                        ModelState.AddModelError("", "La cantidad no pueder ser negativa.");
                        return(pdt);
                    }

B:
                    Random r = new Random();
                    int codigo = r.Next(100000000, 999999999);

                    if (!ValidarCodigo(codigo))
                    {
                        goto B;
                    }

                    pdt.NumeroTarjeta = codigo;

                    var newTarjeta = _mapper.Map <TarjetaCredito>(pdt);
                    newTarjeta.Deuda           = 0;
                    newTarjeta.FechaExpiracion = FechaExpiracion;
                    newTarjeta.FechaPago       = Pago;

                    // await _context.TarjetaCredito.AddAsync(newTarjeta);
                    await _context.SaveChangesAsync();

                    await _tarjetaCreditoRepository.AddAsync(newTarjeta);

                    //await _cuentaRepository.AddAsync(newCuenta);

                    return(null);
                }
                else if (pdt.TipoCuenta == "Prestamo")
                {
                    DateTime fecha      = DateTime.Now;
                    DateTime nuevaFecha = Convert.ToDateTime(fecha);
                    nuevaFecha = nuevaFecha.AddDays(30);

                    if (pdt.Monto == null)
                    {
                        //    pdt.Monto = 0;
                        ModelState.AddModelError("", "Necesita Ingresar el monto del prestamo");
                        return(pdt);
                    }


                    if (pdt.Monto < 0)
                    {
                        ModelState.AddModelError("", "La cantidad no pueder ser negativa.");
                        return(pdt);
                    }

C:
                    Random r = new Random();
                    int codigo = r.Next(100000000, 999999999);
                    if (!ValidarCodigo(codigo))
                    {
                        goto C;
                    }
                    pdt.NumeroPrestamo = codigo;
                    var newPrestamo = _mapper.Map <Prestamos>(pdt);
                    newPrestamo.FechaExpiracion = nuevaFecha;


                    //Agrando monto prestamo a cuenta principal
                    decimal MontoPrestamo = Convert.ToDecimal(newPrestamo.Monto);

                    var     cuentaPrincipal      = _cuentaRepository.GetCuentaAt(id.Value);
                    decimal MontoCuentaPrincipal = Convert.ToDecimal(cuentaPrincipal.Balance);

                    decimal total = MontoCuentaPrincipal + MontoPrestamo;
                    cuentaPrincipal.Balance = total;

                    await _cuentaRepository.Update(cuentaPrincipal);

                    await _repositoryPrestamos.AddAsync(newPrestamo);


                    return(null);
                }
                ModelState.AddModelError("", "Debes agregar algo por favor");
                return(null);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "" + e);
                return(null);
            }
        }