コード例 #1
0
        // PUT: api/Ressource/5
        public void Put(ressClient majRes)
        {
            Ressource ressource = db.Ressource.Where(res => res.ID == majRes.id).FirstOrDefault();

            ressource.Initial  = majRes.initial;
            ressource.Name     = majRes.name;
            ressource.Niveau   = majRes.niveau;
            ressource.Mail     = majRes.mail;
            ressource.Obsolete = false;
            List <Tarification_Ressource> tarRess = db.Tarification_Ressource.Where(t => t.FK_Ressource == majRes.id).ToList();

            foreach (Tarification_Ressource tar in tarRess)
            {
                db.Tarification_Ressource.Attach(tar);
                db.Tarification_Ressource.Remove(tar);
            }
            db.SaveChanges();
            foreach (Int16 idTar in majRes.tarification)
            {
                Tarification_Ressource tarification_ressource = new Tarification_Ressource();
                tarification_ressource.FK_Ressource = majRes.id;
                Tarification tar = db.Tarification.Where(res => res.ID == idTar).FirstOrDefault();
                tarification_ressource.FK_Tarification = tar.ID;
                db.Tarification_Ressource.Add(tarification_ressource);
            }
            db.SaveChanges();
        }
コード例 #2
0
        // POST: api/Ressource
        public void Post(ressClient rss) // Ajout d'une nouvelle ressource
        {
            Ressource newRess = new Ressource();

            newRess.Initial  = rss.initial;
            newRess.Mail     = rss.mail;
            newRess.Name     = rss.name;
            newRess.Niveau   = rss.niveau;
            newRess.Obsolete = false;
            newRess.Date     = DateTime.Now;
            Tarification_Ressource tarRes = new Tarification_Ressource();

            foreach (Int16 idTar in rss.tarification)
            {
                tarRes.FK_Ressource = newRess.ID;
                Tarification tar = db.Tarification.Where(res => res.ID == idTar).FirstOrDefault();
                tarRes.FK_Tarification = tar.ID;
            }
            db.Ressource.Add(newRess);
            db.Tarification_Ressource.Add(tarRes);
            db.SaveChanges();
        }