예제 #1
0
        public static void SendEmail(string emailAdress, Status status, Commande model)
        {
            string s = "";
            s += string.Format("<h4>Sommaire de la commande - {0}</h4>", (model.Status == Status.Prête) ? "Commandée, En attente!" : "En Livraison");

            s += "<table class=\"customTable\">";

            s += "<tr><th class=\"customTable\">Nom du plat</th><th class=\"customTable\">Quantité</th></tr>";

            for (var x = 0; x < model.CommandeItem.Count; x++)
            {
                s += "<tr><td class=\"customTable\">" + model.CommandeItem[x].Plat.Nom + "</td><td class=\"customTable\">" + model.CommandeItem[x].Quantite + "</td></tr>";
            };
            s += "</table>";

            s += "</br >Prix: " + model.Facture.Prix;

            s += "</br >Date de livraison: " + model.DateHeureLivraison.ToString("yyyy-MM-dd");
            s += "</br >Heure de livraison: " + model.DateHeureLivraison.ToString("HH:mm");
            s += "</br >Adresse: " + model.AdresseClient;

            try
            {
                var smtp = new SmtpClient
                {
                    Port = 587,
                    EnableSsl = true,
                    Credentials = new NetworkCredential("*****@*****.**", "DevLivery333"),
                    Host = "smtp.gmail.com"
                };

                var mail = new MailMessage
                {
                    From = new MailAddress("*****@*****.**", "DevLivery"),
                    Subject = "DevLivery - État de votre commande",
                    IsBodyHtml = true,
                    Body = s + @"
                    <br>
                    <br>
                    Le numéro de votre commende est:" + model.NumeroDeCommande
                };

                mail.To.Add(new MailAddress(emailAdress));

                smtp.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #2
0
        public JsonResult Create(Commande model)
        {
            model.ClientId = ((Utilisateur)Session["CurrentUser"]).Id;
            model.NumeroDeCommande = Guid.NewGuid().ToString(); // That order number
            model.DateHeureCreation = DateTime.Now;
            model.Status = Status.Prête;

            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(new
                    {
                        Result = "ERROR",
                        Message = "Le formulaire n'est pas valide"
                    });
                }
                var client = RavenSession.Load<Utilisateur>(model.ClientId);

                client.Adress = model.AdresseClient;
                RavenSession.Store(model);
                RavenSession.SaveChanges();

                // ENVOYER le email au client
                var client = RavenSession.Load<Utilisateur>(model.ClientId);
                NotificationsHelper.SendEmail(client.Email, model.Status, model);

                var url = Url.Action("Index", "Home");

                return Json(new { Result = "OK", Record = model});
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }