public void AddEtablissement(string nom, string adresse)
        {
            Etablissement    etablissement        = new Etablissement();
            EtablissementDAO etablissementManager = new EtablissementDAO();

            etablissement.Nom     = nom;
            etablissement.Adresse = adresse;
            etablissementManager.Create(etablissement);
        }
示例#2
0
        public ActionResult FormEtablissement(string id)
        {
            ActionResult retour = View();

            if (Session["UserID"] == null)
            {
                retour = RedirectToAction("Login");
            }
            else
            {
                EtablissementDAO     etabDao      = new EtablissementDAO();
                TypeEtablissementDAO typesEtabDao = new TypeEtablissementDAO();
                Etablissement        etab         = new Etablissement();
                ViewBag.etablissement = etab;
                List <TypeEtablissement> listeTypesEtablissement = typesEtabDao.RetournerTousLesTypesEtablissement();
                ViewBag.listeTypesEtablissement = listeTypesEtablissement;

                if (Request.HttpMethod == "POST")
                {
                    int               idEtab          = Int32.Parse(Request.Form["idEtab"]);
                    string            nom             = Request.Form["nom"];
                    string            adresse         = Request.Form["adresse"];
                    string            mel             = Request.Form["adresseMel"];
                    string            numeroTelephone = Request.Form["numeroTelephone"];
                    int               idType          = Int32.Parse(Request.Form["idType"]);
                    TypeEtablissement typeEtab        = listeTypesEtablissement.Find(tp => tp.Id == idType);


                    etab = new Etablissement(idEtab, nom, adresse, numeroTelephone, mel, typeEtab);

                    if (idEtab == 0)
                    {
                        etabDao.Create(etab);
                    }
                    else
                    {
                        etabDao.Update(etab);
                    }
                    ViewBag.etablissement = etab;

                    retour = View("FicheEtablissement");
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(id))
                    {
                        if (Int32.TryParse(id, out int idEtab))
                        {
                            if (etabDao.Read(idEtab) != null)
                            {
                                etab = etabDao.Read(idEtab);
                                if ((Request.HttpMethod == "GET") && (Request.Params["action"] != null))
                                {
                                    if (Request.Params["action"] == "del")
                                    {
                                        etabDao.Delete(etab);
                                        retour = RedirectToAction("FicheEtablissement");
                                    }
                                }
                                else
                                {
                                    ViewBag.etablissement = etab;
                                }
                            }
                        }
                    }
                }
            }
            return(retour);
        }