public IHttpActionResult Delete(int IDVUE) { using (A_MAP_OFEntities context = new A_MAP_OFEntities()) { // Informations générales de la vue IEnumerable <VUE> SelectQuery; SelectQuery = from r in context.VUEs where r.IDVUE == IDVUE select r; VUE mVue = (VUE)Generic.Call_Read_FirstOrDefault <VUE>(SelectQuery); // Suppression de ses éléments context.ELEMENTs.RemoveRange(mVue.ELEMENTs); // Suppression de la vue context.VUEs.Remove(mVue); try { Generic.SaveChanges(context); } catch (HttpResponseException ex) { string LibelleErreur = ex.Response.ReasonPhrase.Replace(System.Environment.NewLine, ""); var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = LibelleErreur }; throw new HttpResponseException(resp); }; } return(Ok()); }
public int Post([FromBody] Vue_POST obj_from_javascript) { int IDVUE; // IDVUE autogénéré suite à l'ajout using (A_MAP_OFEntities context = new A_MAP_OFEntities()) { // Récupération de l'id de l'utilisateur en cours int IdUtilisateur = getCurrentIdUser(); // La vue créée ou modifiée VUE mVue; // Si la vue était inexistante if (obj_from_javascript.mVueCore_POST.IDVUE == -1) { // initialisation d'une nouvelle vue mVue = new VUE(); mVue.USER_CREE = getCurrentIdUser(); mVue.DATE_CREE = DateTime.Now; } else { // Récupération de la vue existante IEnumerable <VUE> SelectQuery; // Renvoi l'éventuelle idvue existant (sauf triche js) SelectQuery = from r in context.VUEs where r.USER_CREE == IdUtilisateur && r.IDVUE == obj_from_javascript.mVueCore_POST.IDVUE select r; mVue = (VUE)Generic.Call_Read_FirstOrDefault <VUE>(SelectQuery); } // Création ou mise à jour de la vue. mVue.LIBELLE = obj_from_javascript.mVueCore_POST.LIBELLE; mVue.MAINCONTAINERX = obj_from_javascript.mVueCore_POST.MAINCONTAINERX; mVue.MAINCONTAINERY = obj_from_javascript.mVueCore_POST.MAINCONTAINERY; // Suppression préalable de tous les éléments context.ELEMENTs.RemoveRange(mVue.ELEMENTs); // Création des éléments for (var i = 0; i < obj_from_javascript.mElement_POST.Length; i++) { ELEMENT mELEMENT = new ELEMENT(); mELEMENT.IDELEMENTVUE = obj_from_javascript.mElement_POST[i].IDELEMENTVUE; mELEMENT.IDELEMENTVUEPARENT = obj_from_javascript.mElement_POST[i].IDELEMENTVUEPARENT; mELEMENT.IDOBJET = obj_from_javascript.mElement_POST[i].IDOBJET; mELEMENT.IDTYPEOBJETVUE = obj_from_javascript.mElement_POST[i].IDTYPEOBJETVUE; mELEMENT.LIBELLE = obj_from_javascript.mElement_POST[i].LIBELLE; mELEMENT.X = obj_from_javascript.mElement_POST[i].X; mELEMENT.Y = obj_from_javascript.mElement_POST[i].Y; mELEMENT.X_DELTA = obj_from_javascript.mElement_POST[i].Y_DELTA; mELEMENT.FORME = obj_from_javascript.mElement_POST[i].FORME; mVue.ELEMENTs.Add(mELEMENT); } context.VUEs.Add(mVue); try { Generic.SaveChanges(context); } catch (HttpResponseException ex) { string LibelleErreur = ex.Response.ReasonPhrase.Replace(System.Environment.NewLine, ""); var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed) { ReasonPhrase = LibelleErreur }; throw new HttpResponseException(resp); }; // récupération de l'IDVUE autogénéré IDVUE = mVue.IDVUE; } return(IDVUE); }