public async Task <IActionResult> AgregarBeneficiario(BeneficiarioViewModel agg) { if (agg.NumeroCuenta == null) { return(RedirectToAction("Beneficiario")); } else { var cuenta = await _context.Cuenta.FirstOrDefaultAsync(x => x.NumeroCuenta == agg.NumeroCuenta); if (cuenta != null) { Beneficiario bn = new Beneficiario(); bn.IdUsuarioCliente = agg.IdUsuario; bn.IdUsuarioBeneficiario = cuenta.IdUsuario; await _context.Beneficiario.AddAsync(bn); await _context.SaveChangesAsync(); } } return(RedirectToAction("Beneficiario")); }
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); } }