コード例 #1
0
        public IActionResult Post(EstudianteCursoDTO estudianteCurso)
        {
            //string SendersAddress = "*****@*****.**";

            //string ReceiversAddress = "*****@*****.**";

            //const string SendersPassword = "******";

            //const string subject = "Prueba";



            //const string body = "<body style='margin: 0; padding: 0; '>" +
            //    "<div class='contenedor' style='background-color:red;'>" +
            //    "Inscripcion con exito a las materias" +
            //    "</div>" +
            //    "</body>";
            try
            {
                //SmtpClient smtp = new SmtpClient
                //{
                //    Host = "smtp.gmail.com",
                //    Port = 587,
                //    EnableSsl = true,
                //    DeliveryMethod = SmtpDeliveryMethod.Network,
                //    Credentials = new NetworkCredential(SendersAddress, SendersPassword),
                //    Timeout = 3000
                //};

                //MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);

                ///*PARA AÑADIR TEXTO HTML*/
                //message.IsBodyHtml = true;
                //smtp.Send(message);
                return(new JsonResult(_service.CreateRelacion(estudianteCurso))
                {
                    StatusCode = 200
                });
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
        /*
         * public async Task<CursoCustomDTO> ObtenerCurso(int cursoId)
         * {
         *
         * }*/

        public async Task <EstudianteCurso> CreateRelacion(EstudianteCursoDTO relacion)
        {
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };
            CursoCustomDTO curso;
            Profesor       profesor;
            int            profesorId;

            using (var http = new HttpClient(clientHandler))
            {
                string link = "https://*****:*****@gmail.com";
                string       ReceiversAddress = estudiante.Email;
                const string SendersPassword  = "******";
                string       subject          = "Inscripcion a " + curso.Nombre;

                string texto = "<table style='width: 100%; height: auto; padding: 0; margin:0; border-collapse: collapse;'>" +
                               "<tr>" +
                               "<td style='background-color: #02b8b8'>" +
                               "<div style='color: #34495e; margin: 4% 10% 2%; text-align: center;font-family: sans-serif'>" +
                               "<h2 style='color: #f7f7f7; margin: 0 0 7px'>Hola " + estudiante.Nombre + " " + estudiante.Apellido + "," + "</h2>" +
                               "<h2 style='color: #ffffff; margin: 0 0 7px'>¡SALUDOS DE APRENDIENDO.COM!</h2>" +
                               "</div>" +
                               "</td>" +
                               "</tr>" +
                               "<tr>" +
                               "<td style='background-color: #ecf0f1'> " +
                               "<div style='color: #34495e; margin: 4%; text-align: center;font-family: sans-serif'>" +
                               "<h2 style='color: #000000;'>Tu inscripción al curso " + curso.Nombre + " fue exitosa!</h2>" +
                               "<div style='width: 100%;max-width: 600px;height: 100%;text-align: center; display: inline-block;'>" +
                               "<img style='width: 100%; height: 100%; margin: 0;padding: 0;' src='" + curso.Imagen + "'>" +
                               "<div style='max-width: 600px; margin: 0;padding: 0; width: 100%; text-align: center;color: black;'>" +
                               "<h3 style='margin: 0;padding: 0;margin-top: 10px; '>Profesor del curso: " + profesor.Nombre + " " + profesor.Apellido + "</h3>" +
                               "</div>" +
                               "</div>" +
                               "</div>" +
                               "<div style='width: 100%; text-align: center; height: auto;min-height: 60px; '>" +
                               "<a style='text-decoration: none; font-family: Arial, Helvetica, sans-serif ;border-radius: 5px; padding: 10px; color: white; background-color: #02b8b8' href='http://127.0.0.1:5503/pages/Login.html'>Visitar Nuestra Web</a>" +
                               "</div>" +
                               "</td>" +
                               "</tr>" +
                               "</table>";


                string body = texto;

                SmtpClient smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(SendersAddress, SendersPassword),
                    Timeout               = 5000
                };
                MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
                message.IsBodyHtml = true;
                smtp.Send(message);



                var entity = new EstudianteCurso
                {
                    EstudianteCursoID = relacion.EstudianteCursoID,
                    CursoID           = relacion.CursoID,
                    EstudianteID      = relacion.EstudianteID,
                    Estado            = relacion.Estado
                };
                _repository.Add <EstudianteCurso>(entity);

                return(entity);
            }
        }