public IActionResult Registrar(Participante p)
 {
     if (ModelState.IsValid)
     {
         _context.Add(p);
         _context.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(p));
     }
 }
Пример #2
0
        public IActionResult CrearEvento(Evento e)
        {
            ViewBag.Message = UsuarioController.MsjUsu;
            ViewBag.Rol     = UsuarioController.Rol_usu;
            if (ModelState.IsValid)
            {
                if (e.FechaInicio > DateTime.Now && e.FechaInicio < e.FechaFin)
                {
                    e.estado = "Pendiente";
                    _context.Add(e);
                    _context.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(e));
            }
        }
        public IActionResult RegistroPagoCurso(Tarjeta tar)
        {
            if (ModelState.IsValid)
            {
                var pagos    = _context.Pagos.Where(p => p.ParticipanteId == iduser && p.estado_pago == "Pago Pendiente").ToList();
                var tarjetas = _context.Tarjetas.SingleOrDefault(t => t.NroTarjeta == tar.NroTarjeta && t.CVV == tar.CVV);
                var boleta   = new Boleta();
                //se genera el codigo para la tabla boleta
                int           longitud = 8;
                const string  alfabeto = "0123456789"; //"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
                StringBuilder token    = new StringBuilder();
                Random        rnd      = new Random();

                for (int i = 0; i < longitud; i++)
                {
                    int indice = rnd.Next(alfabeto.Length);
                    codigo_boleta = Int32.Parse(token.Append(alfabeto[indice]).ToString());
                }
                boleta.cod_boleta = codigo_boleta;
                boleta.fec_emi    = DateTime.Now;
                /*                 boleta.cursos_detalle = "CURSO1,CURSO2,CURSO3,"; */
                //funcion split para separar los cursos usando una coma CUACKIZI WAS HERE

                /* foreach (var word in words) {
                 *  System.Console.WriteLine ($"<{word}>");
                 * } */
                boleta.cursos_detalle      = "";
                boleta.montocursos_detalle = "";
                boleta.monto_pagado        = monto_pagar_boleta;

                //recorremos el listado de pagoss
                foreach (Pago p in pagos)
                {
                    //inicializo la tabla con 2 FK
                    var t_part_even = new Participante_Evento();
                    var eventos     = _context.Eventos.SingleOrDefault(e => e.Id == p.EventoId);
                    if (eventos != null)
                    {
                        t_part_even.EventoId       = eventos.Id;
                        t_part_even.ParticipanteId = iduser;
                        t_part_even.Comentario     = "Pendiente";
                        _context.Add(t_part_even);
                        _context.SaveChanges();
                        /* boleta.cursos_detalle = boleta.cursos_detalle + p.Evento.NombreEvento + ","; */
                        boleta.cursos_detalle      = boleta.cursos_detalle + eventos.NombreEvento + ",";
                        boleta.montocursos_detalle = boleta.montocursos_detalle + eventos.Inversion + ",";
                    }
                }
                boleta.cursos_detalle      = boleta.cursos_detalle.Substring(0, boleta.cursos_detalle.Length - 1);
                boleta.montocursos_detalle = boleta.montocursos_detalle.Substring(0, boleta.montocursos_detalle.Length - 1);
                /* Console.WriteLine (substring); */
                _context.Add(boleta);
                _context.SaveChanges();
                foreach (Pago pa in pagos)
                {
                    if (pa.estado_pago == "Pago Pendiente")
                    {
                        /* DateTime.Today.ToString("dd-MM-yyyy"); */
                        pa.estado_pago           = "Cancelado";
                        pa.BoletaId              = boleta.Id;
                        _context.Entry(pa).State = EntityState.Modified;
                        _context.SaveChanges();
                    }
                }

                return(RedirectToAction("CursosInscritos", "Inscripcion"));
            }
            else
            {
                return(RedirectToAction("CursosInscritos", "Inscripcion"));
            }
        }
        public IActionResult PreInscribir(int?idE, int?idU)
        {
            var evento         = _context.Eventos.FirstOrDefault(e => e.Id == idE);
            var usuario        = _context.Participantes.FirstOrDefault(p => p.Id == idU);
            var destino_correo = usuario.Correo;

            iduser = usuario.Id;
            /* idevento = evento.Id; */
            if (usuario != null && evento != null)
            {
                int           longitud = 7;
                const string  alfabeto = "0123456789"; //"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
                StringBuilder token    = new StringBuilder();
                Random        rnd      = new Random();

                for (int i = 0; i < longitud; i++)
                {
                    int indice = rnd.Next(alfabeto.Length);
                    codigo = token.Append(alfabeto[indice]).ToString();
                }

                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

                msg.To.Add(destino_correo);
                msg.Subject         = "Pre Inscripción Curso - ABC";
                msg.SubjectEncoding = System.Text.Encoding.UTF8;
                //ENVIA UNA COPIA DEL CORREO
                msg.Bcc.Add("*****@*****.**");
                //toda estructura html es texto y css
                msg.Body =
                    "<body>" +
                    "<div id='msg'><p>SE HA REALIZADO SU PREINSCRIPCION CON EL SIGUIENTE CÓDIGO DE PAGO: </p><br><strong><h1>" + codigo + "</h1><strong></div><br>" +
                    "<div>Monto a Pagar por el Curso de:</div>" + evento.NombreEvento + "  " + evento.Inversion +
                    "</body>";
                msg.BodyEncoding = System.Text.Encoding.UTF8;
                msg.IsBodyHtml   = true;
                msg.From         = new System.Net.Mail.MailAddress("*****@*****.**");

                //EL CORREO QUE VA A ENVIAR EL MENSAJE DE PRUEBA
                System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();
                cliente.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Peluchin24-10");
                //PUERTO QUE USA GMAIL PARA ENVIAR LOS CORREOS
                cliente.Port      = 587;
                cliente.EnableSsl = true;
                //EL SERVIDOR QUE USA GMAIL PARA LOS CORREOS
                cliente.Host = "smtp.gmail.com"; //smtp particular o institucional, unicamente que pongas correo. pero se necesitas las credenciales smpt
                //eso se especifica en el web.config(appsettings.json)

                cliente.Send(msg);
                //return View();

                var pago = new Pago();
                pago.EventoId       = evento.Id;
                pago.CodPago        = Int32.Parse(codigo);
                pago.ParticipanteId = usuario.Id;
                pago.FechaEmision   = DateTime.Now;
                //DateTime fecha = DateTime.Now.AddDays(7);
                pago.FechaVenc   = DateTime.Now.AddDays(7);
                pago.MontoPago   = evento.Inversion;
                pago.estado_pago = "Pago Pendiente";
                pago.TipoPagoId  = 1;
                //return View();
                _context.Add(pago);
                _context.SaveChanges();
                return(RedirectToAction("PreInscripcionCursos"));
            }
            else
            {
                TempData["Message"] = "Correo invalido";
                //return RecuperarC ("Correo invalido");
                return(NotFound());
            }
        }