Example #1
0
        public ActionResult PendantFermetures()
        {
            if (AdminCommande)
            {
                List <Commande> commandes = new CommandeDAL().CommandesPendantFermetures();
                if (TempData["message"] == null)
                {
                    if (commandes.Count == 0)
                    {
                        TempData["message"] = new Message("Vous n'avez aucune commande pendant des fermetures", TypeMessage.Ok);
                    }
                    else
                    {
                        TempData["message"] = new Message($"Il y a {commandes.Count} commande(s) pendant des fermetures.\nVous pouvez les annuler et prévenir les clients automatiquement par mail", TypeMessage.Ok);
                    }
                }

                List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
                foreach (Commande commande in commandes)
                {
                    listeCommandesViewModel.Add(new CommandeViewModel(commande));
                }
                return(View(listeCommandesViewModel));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
        }
 public void TraiterCommande(int commandeId)
 {
     using (CommandeDAL dal = new CommandeDAL())
     {
         dal.TraiterCommande(commandeId);
     }
 }
 public void ModifierCommande(Commande commande)
 {
     using (CommandeDAL dal = new CommandeDAL())
     {
         dal.ModifierCommande(commande);
     }
 }
 public void OuvrirCommande(int commandeId)
 {
     using (CommandeDAL dal = new CommandeDAL())
     {
         dal.OuvrirCommande(commandeId);
     }
 }
        public List <Commande> ObtenirCommandesSansMassage(bool aTraiter = false)
        {
            List <Commande> commandes;

            using (CommandeDAL dal = new CommandeDAL())
            {
                commandes = dal.ObtenirCommandesSansMassage(aTraiter);
            }
            return(commandes);
        }
        public List <Commande> ObtenirCommandesDuClient(int clientId, bool aTraiter = false)
        {
            List <Commande> commandes;

            using (CommandeDAL dal = new CommandeDAL())
            {
                commandes = dal.ObtenirCommandesDuClient(clientId, aTraiter);
            }
            return(commandes);
        }
        public List <Commande> ObtenirCommandesDeMasseuse(int masseuseId, bool aTraiter = false)
        {
            List <Commande> commandes;

            using (CommandeDAL dal = new CommandeDAL())
            {
                commandes = dal.ObtenirCommandesDeMasseuse(masseuseId, aTraiter);
            }
            return(commandes);
        }
        public int AjouterCommande(Commande commande)
        {
            int id;

            using (CommandeDAL dal = new CommandeDAL())
            {
                id = dal.AjouterCommande(commande);
            }
            return(id);
        }
Example #9
0
        public ActionResult Retirer(int commandeId)
        {
            CommandeDAL commandeDAL = new CommandeDAL();
            Commande    commande    = commandeDAL.Detail(commandeId);

            if (commande != null && (commande.ClientId == Client.Id || AdminCommande))
            {
                commandeDAL.Retirer(commandeId);
            }
            return(Redirect(UrlCourante()));
        }
        public ActionResult AnnulerCommande(int commandeId)
        {
            CommandeDAL commandeDAL = new CommandeDAL();
            Commande    commande    = commandeDAL.Detail(commandeId);

            if (commande != null && commande.ClientId == Client.Id)
            {
                commandeDAL.Annuler(commandeId);
            }
            return(RedirectToAction("Commandes", "Compte"));
        }
Example #11
0
        public ActionResult ReprendreArticles(int commandeId, bool viderPanier)
        {
            CommandeDAL commandeDAL = new CommandeDAL();
            Commande    commande    = commandeDAL.Detail(commandeId);

            if (commande != null && commande.ClientId == Client.Id)
            {
                List <ArticleViewModel> articles = commandeDAL.Articles(commandeId);
                if (viderPanier)
                {
                    new PanierDAL(Client.Id).Supprimer();
                    PanierViewModel.Initialiser();
                    ViewBag.Panier = null; //todo
                }
                List <Article> articlesKo = new List <Article>();
                foreach (var a in articles)
                {
                    if (!PanierViewModel.Ajouter(a.Article, a.Quantite, Client.Id, ProspectGuid))
                    {
                        articlesKo.Add(a.Article);
                    }
                }
                ViewBag.Panier = PanierViewModel;
                TempData["ArticlesNonAjoutes"] = articlesKo;
                if (articlesKo.Count > 0)
                {
                    string dossierImagesArticles = ConfigurationManager.AppSettings["PathImagesArticles"];
                    string message = "Les articles suivants ne peuvent pas être repris car ils ne sont plus disponibles :" +
                                     "<div class=\"gestionCommandeArticle\">" +
                                     "<section class=\"imagesGestionCommande\">";
                    foreach (Article article in articlesKo)
                    {
                        message += "<div class=\"indexArticle\">" +
                                   $"<img src=\"{dossierImagesArticles}/{article.Image}\" alt=\"{article.Nom}\" /> " +
                                   $"<p>{article.Nom}</p>" +
                                   $"</div>";
                    }
                    message += "</section>" +
                               "</div>";
                    TempData["message"] = new Message(message, TypeMessage.Info); // TODO faire plus propre et ailleurs (formatage html propre à la vue)
                }
                else
                {
                    TempData["message"] = new Message($"La reprise des {articles.Count} articles de votre commande s'est correctement réalisée", TypeMessage.Ok);
                }
            }
            RecupererPanierEnBase();
            ViewBag.Panier = PanierViewModel;
            return(RedirectToAction("Index", "Panier"));
        }
Example #12
0
 public ActionResult PendantFermetures(int id)
 {
     if (AdminCommande && id == 0)
     {
         CommandeDAL     commandeDAL            = new CommandeDAL();
         List <Commande> commandes              = commandeDAL.CommandesPendantFermetures();
         List <int>      commandesIdMailInconnu = new List <int>();
         foreach (Commande commande in commandes)
         {
             int commandeId = commande.Id;
             commandeDAL.Annuler(commandeId);
             int clientId = commande.ClientId;
             if (clientId != 0)
             {
                 Client client       = new ClientDAL().Details(clientId);
                 string objetMail    = $"Problème commande {commandeId} : Fermeture de votre foodtruck";
                 string corpsMessage = $"Bonjour {client.Prenom}\n\n" +
                                       $"Vous avez passé la commande numéro {commandeId} pour le {commande.DateRetrait.ToString("dddd dd MMMM yyyy à HH:mm").Replace(":", "h")} et nous vous en remercions.\n\n" +
                                       $"Malheureusement nous ne sommes plus ouvert pendant votre horaire de retrait et nous avons été contraint de l'annuler.\n\n" +
                                       $"Nous vous invitons à choisir un autre créneau de retrait (vous pouvez dupliquer votre commande annulée dans votre espace client).\n\n" +
                                       $"Nous vous prions de nous excuser pour la gène occasionnée.\n\n" +
                                       $"Bien cordialement\n" +
                                       $"Votre équipe Foodtrucklyon";
                 string adresseMailClient = client.Email;
                 Utilitaire.EnvoieMail(adresseMailClient, objetMail, corpsMessage);
             }
             else
             {
                 commandesIdMailInconnu.Add(commandeId);
             }
         }
         string message = $"Les {commandes.Count} commande(s) ont bien été annulées et les clients ont reçu un mail";
         if (commandesIdMailInconnu.Count != 0)
         {
             message += "\nAttention :\nLes clients des commandes qui suivent n'ont pas pu être prévenus car ils n'ont pas rensigné les adresses mail :\n";
             foreach (int commandeId in commandesIdMailInconnu)
             {
                 message += $"-{commandeId}-  ";
             }
         }
         TempData["message"] = new Message(message, TypeMessage.Ok);
         return(RedirectToAction(ActionNom));
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
     }
 }
        public ActionResult CommandeVersPdf(int commandeId)
        {
            Commande commande = new CommandeDAL().Detail(commandeId);

            if (commande != null && !commande.Annulation && commande.Retrait && (commande.ClientId == Client.Id || AdminCommande))
            {
                Facture     facture    = new FactureDAL().DetailsCommande(commandeId);
                HtmlToPdf   htmlToPdf  = new HtmlToPdf();
                PdfDocument facturePdf = htmlToPdf.ConvertUrl($"{Request.Url.Scheme}://{Request.Url.Authority}/{ControllerNom}/Guid/{facture.Guid}");
                return(File(facturePdf.Save(), "application/pdf", $"factureFoodTruckLyon-commande{commandeId}.pdf"));
            }
            else
            {
                TempData["message"] = new Message("Vous n'avez pas de facture associée à ce numéro de commande", TypeMessage.Erreur);
                return(Redirect(UrlPrecedente()));
            }
        }
        public ActionResult Guid(string id)
        {
            Facture facture = new FactureDAL().Details(id);

            if (facture != null)
            {
                Commande          commande   = new CommandeDAL().Detail(facture.CommandeId);
                CommandeViewModel commandeVM = new CommandeViewModel(commande);
                FactureViewModel  factureVM  = new FactureViewModel(commandeVM);
                ViewBag.FactureId = facture.Id;
                return(View(factureVM));
            }
            else
            {
                return(View(null as FactureViewModel));
            }
        }
        public ActionResult Index()
        {
            if (PanierViewModel.ArticlesDetailsViewModel.Count != 0)
            {
                ViewBag.PanierLatteralDesactive = true;
                DateTime maintenant = DateTime.Now;
                List <PlageHoraireRetrait> plagesHorairesRetrait = maintenant.PlageHoraireRetrait();

                // obtention nombre de commandes à retirer dans chaque creneaux ouvert et desactivation si = nombre max
                int         maxCommandesHeure = int.Parse(ConfigurationManager.AppSettings["NombreDeCommandesMaxParHeure"]);
                CommandeDAL commandeDAL       = new CommandeDAL();
                PanierViewModel.Creneaux = new List <Creneau>();
                foreach (PlageHoraireRetrait plage in plagesHorairesRetrait)
                {
                    int maxCommandesCreneau = (int)Math.Ceiling(maxCommandesHeure * plage.Pas.TotalMinutes / 60);
                    foreach (DateTime date in plage.Dates)
                    {
                        Creneau creneau = new Creneau
                        {
                            DateRetrait = date,
                            CommandesPossiblesRestantes = maxCommandesCreneau - commandeDAL.NombreCommandes(date)
                        };
                        PanierViewModel.Creneaux.Add(creneau);
                    }
                }

                int index = ((List <string>)Session["Url"]).Count - 2;
                if (index < 0)
                {
                    index = 0;
                }
                if (Client.Id == 0 && PanierViewModel.ArticlesDetailsViewModel.Count > 0 && ((List <string>)Session["Url"])[index] != "/Panier/Index")
                {
                    TempData["message"] = new Message("Vous n'êtes pas connecté à votre compte.\nVous pouvez commander mais\n- vous ne bénéficierez pas du programme de fidélité\n- votre commande ne sera pas dans votre historique\n- vous ne recevrez pas de confirmation de votre commande", TypeMessage.Info);
                }
                return(View(PanierViewModel));
            }
            else
            {
                TempData["message"] = new Message("Vous n'avez pas d'article dans votre panier\nVoyez notre carte pour faire votre choix.", TypeMessage.Info);
                return(RedirectToAction("Index", "Article"));
            }
        }
Example #16
0
 public ActionResult Recherche()
 {
     if (AdminCommande)
     {
         ViewBag.DateDebut = DateTime.Today;
         ViewBag.DateFin   = DateTime.Today;
         List <Commande>          commandes = new CommandeDAL().CommandesRecherche("", DateTime.Today, DateTime.Today.AddDays(3));
         List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
         foreach (Commande commande in commandes)
         {
             listeCommandesViewModel.Add(new CommandeViewModel(commande));
         }
         return(View(listeCommandesViewModel));
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
     }
 }
Example #17
0
 public ActionResult AStatuer()
 {
     if (AdminCommande)
     {
         List <Commande> commandes = new CommandeDAL().CommandesAStatuer();
         if (commandes.Count == 0)
         {
             TempData["message"] = new Message("Vous n'avez aucune commande à statuer", TypeMessage.Info);
         }
         List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
         foreach (Commande commande in commandes)
         {
             listeCommandesViewModel.Add(new CommandeViewModel(commande));
         }
         return(View(listeCommandesViewModel));
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
     }
 }
Example #18
0
        public ActionResult Liste(string id)
        {
            CommandeDAL     commandeDAL = new CommandeDAL();
            List <Commande> commandes   = null;

            ViewBag.ModeAdmin  = false;
            ViewBag.ModeClient = true;
            switch (id)
            {
            case "dernieres":
                const int       nombreDernieresCommandes = 3;
                List <Commande> commandesenCours         = commandeDAL.CommandesEnCoursClient(Client.Id);
                TempData["MessageCommandes"] = "Vos dernières commandes";
                commandes = commandeDAL.CommandesClient(Client.Id).Except(commandesenCours, new CommandeEqualityComparer()).Take(nombreDernieresCommandes).ToList();
                break;

            case "enCours":
                TempData["MessageCommandes"] = "Vos commandes en cours";
                commandes = commandeDAL.CommandesEnCoursClient(Client.Id);
                break;

            case "toutes":
                TempData["MessageCommandes"] = "Toutes vos commandes";
                commandes = commandeDAL.CommandesClient(Client.Id);
                break;
            }
            if (commandes != null && commandes.Count != 0)
            {
                List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
                foreach (Commande commande in commandes)
                {
                    listeCommandesViewModel.Add(new CommandeViewModel(commande));
                }
                return(PartialView(listeCommandesViewModel));
            }
            else
            {
                return(null);
            }
        }
Example #19
0
        public ActionResult Recherche(string recherche, DateTime?dateDebut, DateTime?dateFin)
        {
            if (AdminCommande)
            {
                ViewBag.Recherche = recherche;
                ViewBag.DateDebut = dateDebut;
                ViewBag.DateFin   = dateFin;

                string[]          tabRecherche = recherche.Split(' ');
                List <Commande>[] tabCommandes = new List <Commande> [tabRecherche.Length];

                for (int i = 0; i < tabRecherche.Length; i++)
                {
                    tabCommandes[i] = new CommandeDAL().CommandesRecherche(tabRecherche[i], dateDebut, dateFin);
                }

                List <Commande> commandes = tabCommandes[0];
                for (int i = 1; i < tabCommandes.Length; i++)
                {
                    commandes = commandes.Intersect(tabCommandes[i], new CommandeEqualityComparer()).ToList();
                }
                if (commandes.Count == 0)
                {
                    TempData["message"] = new Message("Aucune commande ne correspond à votre recherche.\nVeuillez élargir vos critères de recherche", TypeMessage.Avertissement);
                }

                List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
                foreach (Commande commande in commandes)
                {
                    listeCommandesViewModel.Add(new CommandeViewModel(commande));
                }
                return(View(listeCommandesViewModel));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
        }
Example #20
0
        public ActionResult EnCours()
        {
            const int fouchetteHeures = 4;

            if (AdminCommande)
            {
                List <Commande> commandes = new CommandeDAL().CommandesEnCours(fouchetteHeures);
                if (commandes.Count == 0)
                {
                    TempData["message"] = new Message("Vous n'avez aucune commande en cours", TypeMessage.Info);
                }
                List <CommandeViewModel> listeCommandesViewModel = new List <CommandeViewModel>();
                foreach (Commande commande in commandes)
                {
                    listeCommandesViewModel.Add(new CommandeViewModel(commande));
                }
                return(View(listeCommandesViewModel));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
        }
        public ActionResult Profil(string ancienEmail, string login, string email, string ancienMdp, string nom, string prenom, string telephone, string mdp, string mdp2)
        {
            ViewBag.Login     = login;
            ViewBag.Email     = email;
            ViewBag.Nom       = nom;
            ViewBag.Prenom    = prenom;
            ViewBag.Telephone = telephone;
            ViewBag.Mdp       = mdp;
            ViewBag.AncienMdp = ancienMdp;

            StringBuilder messageFabrique = new StringBuilder();

            ClientDAL clientDAL = new ClientDAL();
            Client    client    = clientDAL.Connexion(ancienEmail, ancienMdp);
            bool      erreur    = false;

            if (client == null)
            {
                messageFabrique.Append("L'ancien mot de passe n'est pas correct.");
                erreur            = true;
                ViewBag.AncienMdp = "";
            }
            else
            {
                int verifClientId = clientDAL.ExisteLogin(login);
                if (verifClientId != 0 && verifClientId != Client.Id)
                {
                    ViewBag.Login = "";
                    messageFabrique.Append("Le nouveau nom d'utilisateur est déjà utilisé.\n");
                    erreur = true;
                }
                verifClientId = clientDAL.ExisteEmail(email);
                if (verifClientId != 0 && verifClientId != Client.Id)
                {
                    ViewBag.Email = "";
                    messageFabrique.Append("Le nouvel Email est déjà utilisé.\n");
                    erreur = true;
                }
                string nouveauMdp = "";
                if (mdp == "" && mdp2 == "")
                {
                    nouveauMdp = ancienMdp;
                }
                else if (VerifMdp(mdp, mdp2))
                {
                    nouveauMdp = mdp;
                }
                else
                {
                    ViewBag.Mdp = "";
                    messageFabrique.Append("Mauvais choix de mots de passe. (minimum 8 caractères et identiques)");
                    erreur = true;
                }
                if (!erreur)
                {
                    if (clientDAL.Modification(client.Id, nouveauMdp, login, email, nom, prenom, telephone) == 1)
                    {
                        messageFabrique.Append("La modification du profil a bien été prise en compte.");
                        Client = clientDAL.Connexion(email, nouveauMdp);
                    }
                    else
                    {
                        messageFabrique.Append("Une erreur s'est produite lors de la mise à jour de vos données");
                        erreur = true;
                    }
                }
            }
            string message = messageFabrique.ToString();

            if (erreur)
            {
                TempData["message"] = new Message(message, TypeMessage.Erreur);
            }
            else
            {
                TempData["message"] = new Message(message, TypeMessage.Ok);
            }

            CommandeDAL commandeDAL = new CommandeDAL();

            ViewBag.RemiseTotalClient = commandeDAL.RemiseTotaleClient(Client.Id); //todo vérifier si code utile
            return(View(Client));
        }
        public ActionResult OubliMotDePasse(string action, string email, string mdp, string mdp2)
        {
            if (action == "generationMail")
            {
                int    dureeValidite    = int.Parse(ConfigurationManager.AppSettings["DureeValiditeLienReinitialisationMotDePasse"]);
                string codeVerification = Guid.NewGuid().ToString("n") + email.GetHash();
                string url    = HttpContext.Request.Url.ToString() + '/' + codeVerification;
                Client client = new ClientDAL().Details(email);
                if (client != null)
                {
                    DateTime finValidite       = DateTime.Now.AddMinutes(dureeValidite);
                    string   stringFinValidite = finValidite.ToString("dddd dd MMMM yyyy à HH:mm").Replace(":", "h");
                    new OubliMotDePasseDAL().Ajouter(client.Id, codeVerification, DateTime.Now.AddMinutes(dureeValidite));
                    string sujetMail = "Procédure de réinitialisation de votre mot de passe";
                    string message   = "Bonjour\n" +
                                       "Vous avez oublié votre mot de passe et avez demandé à le réinitialiser.\n" +
                                       "Si vous êtes bien à l'origine de cette demande, veuillez cliquer sur le lien suivant ou recopier l'adresse dans votre navigateur :\n" +
                                       "\n" +
                                       url +
                                       "\n\nVous serez alors redirigé vers une page de réinitialisation de votre mot de passe.\n" +
                                       $"Attention, ce lien expirera le {stringFinValidite} et n'est valable qu'une seule fois";

                    if (Utilitaire.EnvoieMail(email, sujetMail, message))
                    {
                        TempData["message"] = new Message($"Un email de réinitialisation de votre mot de passe vient de vous être envoyé.\nIl expirera dans {dureeValidite} minutes.", TypeMessage.Info);
                    }
                    else
                    {
                        TempData["message"] = new Message("Erreur dans l'envoi du mail.\nVeuillez réessayer dans quelques instants", TypeMessage.Erreur);
                    }
                }
                else
                {
                    TempData["message"] = new Message("Nous n'avons pas de compte client avec cette adresse email.\nMerci de vérifier votre saisie", TypeMessage.Erreur);
                }

                return(RedirectToAction("Connexion", "Compte"));
            }
            else if (action == "changementMotDePasse")
            {
                if (VerifMdp(mdp, mdp2))
                {
                    ClientDAL clientDAL = new ClientDAL();
                    if (clientDAL.Modification(Client.Id, mdp) == 1)
                    {
                        TempData["message"] = new Message("La modification de votre mot de passe a bien été prise en compte", TypeMessage.Ok);
                    }
                }
                else
                {
                    TempData["message"] = new Message("Mauvais choix de mots de passe.\nVeuillez réessayer (minimum 8 caractères et identiques)", TypeMessage.Erreur);
                    return(View());
                }

                CommandeDAL commandeDAL = new CommandeDAL();
                ViewBag.RemiseTotalClient = commandeDAL.RemiseTotaleClient(Client.Id);
                return(RedirectToAction("Connexion", "Compte"));
            }
            else
            {
                return(RedirectToAction("Connexion", "Compte"));
            }
        }