Ejemplo n.º 1
0
        public ActionResult Index(RepresentantViewModel viewModel, string returnUrl)
        {
            int idElement = 0;

            if (Request.Form["btn-login"] != null)
            {
                if (ModelState.IsValid)
                {
                    Representant representant = dal.Authentifier(viewModel.Representant.Courriel, viewModel.Representant.MotDePasse);
                    if (representant != null)
                    {
                        Session["representant"] = representant;


                        FormsAuthentication.SetAuthCookie(representant.Id.ToString(), false);
                        if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        ElementListe element = new ElementListe();
                        idElement = dal.ajouterElement(element);
                        List <ElementListe> Liste = dal.ObtenirElements();
                        return(RedirectToAction("Tableau", "Accueil"));
                    }
                    ModelState.AddModelError("Utilisateur.Courriel", "Compte inexistant.");
                }
                return(View("~/Views/Accueil/Index.cshtml", viewModel));
            }
            else if (Request.Form["btnCreer"] != null)
            {
                CreerCompte(viewModel.Representant);
            }
            return(View("~/Views/Accueil/Index.cshtml", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult AjoutRepresentant(RepresentantViewModel representantViewModel)
        {
            Utilitaires utilitaire = new Utilitaires();

            try
            {
                var    file     = Request.Files[0];
                string fileName = file.FileName;
                string filePath = Path.GetFullPath(fileName);
                representantViewModel.Representant.Photo = utilitaire.convertir(filePath);
            }
            catch (Exception)
            {
                ModelState.AddModelError("PhotoManquante", "La photo est soit manquante ou incompatible.");
            }

            try
            {
                dal.AjouterRepresentant(representantViewModel.Representant);
            }
            catch (Exception)
            {
                ModelState.AddModelError("erreur", "Une erreur s'est produite, Veuillez recommencer.");
            }


            return(View("AjoutRepresentant"));
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            RepresentantViewModel viewModel = new RepresentantViewModel {
                Authentifie = HttpContext.User.Identity.IsAuthenticated
            };

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                viewModel.Representant = dal.ObtenirRepresentant(HttpContext.User.Identity.Name);
            }
            return(View(viewModel));
        }