public async Task <ActionResult <TypeEtablissement> > PostTypeEtablissement(TypeEtablissement typeEtablissement)
        {
            _context.TypeEtablissements.Add(typeEtablissement);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTypeEtablissement", new { id = typeEtablissement.Id }, typeEtablissement));
        }
示例#2
0
        public override Etablissement Read(int id)
        {
            Etablissement etablissement = null;
            SqlCommand    command       = Connexion.GetInstance().CreateCommand();

            command.CommandText = "SELECT * FROM etablissement WHERE id = @id";
            command.Parameters.AddWithValue("@id", id);
            // Lecture des résultats
            SqlDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                int    idEtablissement = id;
                string nom             = dataReader.GetString(1);
                string adresse         = dataReader.GetString(2);
                string numeroTelephone = dataReader.GetString(3);
                string mel             = dataReader.GetString(4);
                int    idType          = dataReader.GetInt32(5);
                dataReader.Close();

                TypeEtablissementDAO typeEtabDAO = new TypeEtablissementDAO();
                TypeEtablissement    typeEtab    = typeEtabDAO.Read(idType);

                etablissement = new Etablissement(idEtablissement, nom, adresse, numeroTelephone, mel, typeEtab);
            }

            return(etablissement);
        }
        public CreateEtablissementViewModel()
        {
            lTypeEtablissement = new TypeEtablissement().types;
            lPays          = new Pays().lPays;
            lJoursSemaines = new JoursSemaine().lJours;
            this.Etab      = new Etablissement();
            this.lHoraire  = new List <Horaire>();

            this.Photos = new PhotoGeneriqueViewModel[NombrePhotos];
            for (int i = 0; i < NombrePhotos; i++)
            {
                Photos[i] = new PhotoGeneriqueViewModel();
            }
        }
示例#4
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);
        }
 public EditEtablissementViewModel()
 {
     lTypeEtablissement = new TypeEtablissement().types;
     lPays          = new Pays().lPays;
     lJoursSemaines = new JoursSemaine().lJours;
 }
        public async Task <ActionResult <TypeEtablissement> > PutTypeEtablissement(long id, TypeEtablissement typeEtablissement)
        {
            if (id != typeEtablissement.Id)
            {
                return(BadRequest());
            }
            _context.Entry(typeEtablissement).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TypeEtablissementExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            //return NoContent();
            return(typeEtablissement);
        }