コード例 #1
0
        public ActionResult Create(ComplaintViewModel comp)
        {
            complaint c = new complaint();

            c.Description   = comp.Description;
            c.creationDate  = DateTime.Now;
            c.Subject       = comp.Subject;
            c.importanceLvl = comp.importanceLvl;
            c.MyUser_idUser = (int)comp.MyUser_idUser;
            //c.user = us.GetById((int)comp.MyUser_idUser);
            cs.Add(c);
            cs.Commit();

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <ActionResult> Create(EmailFormModel model)
        {
            if (ModelState.IsValid)
            {
                var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                var message = new MailMessage();
                message.To.Add(new MailAddress(model.ToEmail));        // replace with valid value _receiver
                message.From       = new MailAddress(model.FromEmail); // replace with valid value _ sender
                message.Subject    = "Answer about your Complaint";
                message.Body       = string.Format(body, model.FromName, model.FromEmail, model.Message);
                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******", // replace with valid value
                        Password = "******"                // replace with valid value
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;

                    try
                    {
                        await smtp.SendMailAsync(message);

                        if (Session["complaint"] != null)
                        {
                            complaint cv = Session["complaint"] as complaint;
                            complaint c  = cs.GetById(cv.id);
                            c.gere = true;
                            cs.Update(c);
                            cs.Commit();
                            Session["complaint"] = null;
                        }
                    }
                    catch (SmtpFailedRecipientsException e)
                    {
                        Console.WriteLine("erreur mail not send !  s" + e.StatusCode);
                        return(View());
                    }

                    return(RedirectToAction("Sent"));
                }
            }
            return(View(model));
        }