Ejemplo n.º 1
0
        public ActionResult RegisterSalon(ViewModelFormAddSalon model)
        {
            if (ModelState.IsValid)
            {

                int idSalon = Bdd.AddSalon(model);
                if (idSalon == 0)
                {
                    //Exception
                    ModelState.AddModelError("Email", "Erreur inconnue");
                    model.CreateListeAbonnements(Bdd.GetAbonnements());
                    return View(model);
                }

                int idManager = Bdd.AddManager(new Manager
                {
                    Email = model.Email,
                    Genre = model.GenreId == 1,
                    Nom = model.Nom,
                    Prenom = model.Prenom,
                    Password = model.Password.ToMd5(),
                    IdRole = 3,
                    IdSalon = idSalon
                });

                if (idManager == 0)
                {
                    //Exception
                    ModelState.AddModelError("Email", "Erreur inconnue");
                    model.CreateListeAbonnements(Bdd.GetAbonnements());
                    return View(model);
                }
                
                //On est ok
                FormsAuthentication.SetAuthCookie(idManager.ToString(), false);
                return RedirectToRoute("Backend_salon_index", new {id = idSalon });
            }

            model.CreateListeAbonnements(Bdd.GetAbonnements());
            return View(model);
        }