Ejemplo n.º 1
0
        public async Task <IActionResult> Answer(int?id, ReplyAnswerVM answerVM)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Models.Reply reply = await _db.Replies.FindAsync(id);

            if (reply == null)
            {
                return(NotFound());
            }
            answerVM.Reply = reply;
            if (!ModelState.IsValid)
            {
                return(View(answerVM));
            }

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**", "No-Reply");
            mail.To.Add(new MailAddress(reply.Email));

            mail.Subject    = answerVM.Subject;
            mail.Body       = $"<h2>Hi {reply.Name}</h2> <p>{answerVM.Message}</p>";
            mail.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();

            smtp.Host      = "smtp.gmail.com";
            smtp.Port      = 587;
            smtp.EnableSsl = true;

            smtp.Credentials = new NetworkCredential("*****@*****.**", "kb6853917");
            smtp.Send(mail);

            if (reply.Checked == false)
            {
                reply.Checked = true;
            }
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Answer(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Models.Reply reply = await _db.Replies.FindAsync(id);

            if (reply == null)
            {
                return(NotFound());
            }

            ReplyAnswerVM answerVM = new ReplyAnswerVM
            {
                Reply = reply
            };

            return(View(answerVM));
        }