Beispiel #1
0
        public IHttpActionResult Post([FromBody] TutoDone_POST mTutoDone_POST)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Récupération de l'id de l'utilisateur en cours

                int IdUtilisateur = getCurrentIdUser();

                // création de l'objet

                TUTODONE mTutoDone = new TUTODONE();
                mTutoDone.IDTUTO        = mTutoDone_POST.idTutoDone;
                mTutoDone.IDUSER        = IdUtilisateur;
                mTutoDone.DATE_CREATION = DateTime.Now;
                context.TUTODONEs.Add(mTutoDone);

                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());
            }
        }
Beispiel #2
0
        public IHttpActionResult Post([FromBody] TypeObjet_POST obj_from_javascript)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // création de l'objet

                TYPEOBJET mTypeObjet = new TYPEOBJET();
                mTypeObjet.LIBELLE     = obj_from_javascript.LIBELLE;
                mTypeObjet.FAVORISMENU = obj_from_javascript.FAVORISMENU;
                mTypeObjet.ICONE       = obj_from_javascript.ICONE;
                context.TYPEOBJET.Add(mTypeObjet);

                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());
        }
Beispiel #3
0
        public object GET([FromUri] string ColonnesAffichees = "", [FromUri] string FiltreLibelle = "")
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                IEnumerable <object> SelectQuery;

                // SELECT

                switch (ColonnesAffichees)
                {
                case "Toutes":

                    SelectQuery = from r in context.TYPEOBJET
                                  select new
                    {
                        IDTYPEOBJET     = r.IDTYPEOBJET,
                        LIBELLE         = r.LIBELLE,
                        FAVORISMENUtrim = r.FAVORISMENU.Trim(),
                        ICONE           = r.ICONE
                    };
                    break;

                case "Libelle":

                    if (FiltreLibelle != "")
                    {
                        SelectQuery = from r in context.TYPEOBJET
                                      // select new { IDTYPEOBJET = r.IDTYPEOBJET };
                                      where r.LIBELLE.Contains(FiltreLibelle)
                                      select r.LIBELLE.ToString();
                    }
                    else
                    {
                        SelectQuery = from r in context.TYPEOBJET
                                      // select new { IDTYPEOBJET = r.IDTYPEOBJET };
                                      select r.LIBELLE.ToString();
                    }


                    break;

                default:
                    SelectQuery = from r in context.TYPEOBJET
                                  select new
                    {
                        IDTYPEOBJET     = r.IDTYPEOBJET,
                        LIBELLE         = r.LIBELLE,
                        FAVORISMENUtrim = r.FAVORISMENU.Trim(),
                        ICONE           = r.ICONE
                    };
                    break;
                }

                return(Generic.Call_Read_ToList <object>(SelectQuery));
            }
        }
Beispiel #4
0
        public object GET(int IDTYPEOBJET, [FromUri] string term = "")
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                IEnumerable <string> SelectQuery;

                SelectQuery = (from r in context.OBJET      // Les objets ...
                               where r.NOM.Contains(term) && // ...dont le nom contient les termes saisis par l'utilisateur,
                               r.IDTYPEOBJET == IDTYPEOBJET // ...et pour le type donné
                               select r.NOM);

                return(Generic.Call_Read_ToList <string>(SelectQuery));
            }
        }
Beispiel #5
0
        public object GET()
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Récupération de l'id de l'utilisateur en cours
                int IdUtilisateur = getCurrentIdUser();

                // Appel de la procédure stockée
                IEnumerable <object> SelectQuery;
                SelectQuery = context.LISTETUTOS(IdUtilisateur);

                return(Generic.Call_Read_ToList <Object>(SelectQuery));
            }
        }
Beispiel #6
0
        public object GET_Full(int IDVUE)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Informations générales de la vue

                IEnumerable <object> SelectQuery;

                SelectQuery = from r in context.VUEs
                              where r.IDVUE == IDVUE
                              select new {
                    r.IDVUE,
                    r.LIBELLE,
                    r.MAINCONTAINERX,
                    r.MAINCONTAINERY
                };

                var Vue = Generic.Call_Read_FirstOrDefault <Object>(SelectQuery);

                // Elements de la vue

                IEnumerable <object> SelectQuery2;

                SelectQuery2 = from r in context.ELEMENTs
                               where r.IDVUE == IDVUE
                               select new {
                    r.IDVUE,
                    r.IDELEMENTVUE,
                    r.IDELEMENTVUEPARENT,
                    r.IDTYPEOBJETVUE,
                    r.IDOBJET,
                    r.LIBELLE,
                    r.FORME,
                    r.X,
                    r.Y,
                    r.X_DELTA,
                    r.Y_DELTA
                };

                var ListeElement = Generic.Call_Read_ToList <Object>(SelectQuery2);

                return(new {
                    Vue = Vue,
                    ListeElement = ListeElement
                });
            }
        }
Beispiel #7
0
        public object GETIDOBJET([FromUri] int IDTYPEOBJET, [FromUri] string NOMOBJET)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                IEnumerable <int> SelectQuery;

                SelectQuery = (from r in context.OBJET      // Les objets ...
                               where r.NOM == NOMOBJET && // ...dont le nom contient les termes saisis par l'utilisateur,
                               r.IDTYPEOBJET == IDTYPEOBJET // ...et pour le type donné
                               select r.IDOBJET);

                var resultat = Generic.Call_Read_FirstOrDefault <int>(SelectQuery);

                // Si l'objet n'existe pas

                if ((int)resultat == 0)
                {
                    // Création

                    OBJET mObjet = new OBJET();
                    mObjet.IDTYPEOBJET = IDTYPEOBJET;
                    mObjet.NOM         = NOMOBJET;

                    context.OBJET.Add(mObjet);

                    // Enregistrement effectif

                    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);
                    };

                    resultat = mObjet.IDOBJET;
                }

                return(new { resultat });
            }
        }
Beispiel #8
0
        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());
        }
Beispiel #9
0
        public object GET([FromUri] string NOMVUE = "")
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Récupération de l'id de l'utilisateur en cours

                int IdUtilisateur = getCurrentIdUser();

                // Si aucun argument n'a été passé :

                if (NOMVUE == "")
                {
                    IEnumerable <object> SelectQuery;

                    // Toutes les vues de l'utilisateurs

                    SelectQuery = from r in context.VUEs
                                  where r.USER_CREE == IdUtilisateur
                                  select new { r.IDVUE, r.LIBELLE };

                    return(Generic.Call_Read_ToList <Object>(SelectQuery));
                }
                else
                {
                    IEnumerable <int> SelectQuery;

                    // Renvoi l'éventuelle idvue existant
                    SelectQuery = from r in context.VUEs
                                  where
                                  r.USER_CREE == IdUtilisateur &&
                                  r.LIBELLE == NOMVUE
                                  select r.IDVUE;

                    var resultat = Generic.Call_Read_FirstOrDefault <int>(SelectQuery);

                    return(new { resultat });
                }
            }
        }
Beispiel #10
0
        public object STEPGET(int IDTUTO)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                IEnumerable <object> SelectQuery;

                // SELECT

                SelectQuery = from r in context.TUTOSTEPs
                              where r.IDTUTO == IDTUTO
                              orderby r.ORDRE ascending
                              select new
                {
                    IDTUTOSTEP      = r.IDTUTOSTEP,
                    IDTUTO          = r.IDTUTO,
                    INDICATION      = r.INDICATION,
                    IDEVENTTOLISTEN = r.IDEVENTTOLISTEN,
                    JSFONCTION      = r.JSFONCTION
                };

                return(Generic.Call_Read_ToList <object>(SelectQuery));
            }
        }
Beispiel #11
0
        public IHttpActionResult PUT_NonFavoris(int IDTYPEOBJET)
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                var c = (TYPEOBJET)Generic.Call_Read_FirstOrDefault <TYPEOBJET>((from r in context.TYPEOBJET
                                                                                 where r.IDTYPEOBJET == IDTYPEOBJET
                                                                                 select r));
                // si le type d'objet n'existe pas
                if (c == null)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed)
                    {
                        ReasonPhrase = "Le type d'objet " + IDTYPEOBJET + " n'existe pas."
                    };
                    throw new HttpResponseException(resp);
                }

                // passage en non favoris
                c.FAVORISMENU = "N";

                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());
        }
Beispiel #12
0
        public object GETSCORE()
        {
            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Récupération de l'id de l'utilisateur en cours

                int IdUtilisateur = getCurrentIdUser();

                // Calcul du nombre de tuto réalisé par l'utilisateur

                IEnumerable <int> SelectQuery;

                SelectQuery = from r in context.TUTODONEs
                              where r.IDUSER == IdUtilisateur
                              group r by r.IDTUTO into gr
                              select gr.Key;

                int NbTutoDone = Generic.Call_Read_Count <int>(SelectQuery);

                // Calcul du nombre de tuto total

                IEnumerable <int> SelectQuery2;

                SelectQuery2 = from r in context.TUTOes
                               select r.IDTUTO;

                int NbTutoTotal = Generic.Call_Read_Count <int>(SelectQuery2);


                decimal PourcentageRealise = ((decimal)NbTutoDone / (decimal)NbTutoTotal) * 100;

                // Pourcentage de tuto réalisé

                return(new { NbTutoDone = PourcentageRealise });
            }
        }
        public ActionResult Login(Utilisateur model, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            int IdUtilisateur = 0;

            // Vérification de l'existence du mot de passe et du nom d'utilisateur

            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                try
                {
                    // Recherche du pseudo et du mot de passe

                    var c = (from r in context.USERs
                             where (r.NOM == model.Nom)
                             select r.MOTDEPASSE).SingleOrDefault();

                    if (c == null) // Le nom d'utilisateur n'existe pas
                    {
                        // éjection

                        ModelState.AddModelError(string.Empty, "Authentification incorrecte");
                        return(View(model));
                    }
                    else   // Si l'utilisateur existe
                    {
                        // calcul du hash de la saisie

                        string hash_code_mdp_soumis = GetHash(model.MotDePasse);

                        // vérification que le hash correspond à ce qui existe en base

                        if (hash_code_mdp_soumis != c)
                        {
                            // éjection

                            ModelState.AddModelError(string.Empty, "Authentification incorrecte");
                            return(View(model));
                        }
                    }

                    // Succès de l'authentification.

                    // Récupération de l'id de l'utilisateur
                    IdUtilisateur = (from r in context.USERs
                                     where (r.NOM == model.Nom)
                                     select r.IDUSER).SingleOrDefault();
                }
                catch (DbUpdateException ex)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed)
                    {
                        ReasonPhrase = ex.InnerException.InnerException.Message.Replace(System.Environment.NewLine, "")
                    };

                    ModelState.AddModelError(string.Empty, "Connexion impossible");
                    return(View(model));
                }
            }

            // L'authentification est réussie,
            // injecter les informations utilisateur dans le cookie d'authentification :
            var userClaims = new List <Claim>();

            // Identifiant utilisateur :
            userClaims.Add(new Claim(ClaimTypes.NameIdentifier, model.Nom));
            // Id d'utilisateur
            userClaims.Add(new Claim(ClaimTypes.Name, IdUtilisateur.ToString()));

            // Rôles utilisateur :
            userClaims.AddRange(LoadRoles(model.Nom));
            var claimsIdentity        = new ClaimsIdentity(userClaims, DefaultAuthenticationTypes.ApplicationCookie);
            var ctx                   = Request.GetOwinContext();
            var authenticationManager = ctx.Authentication;

            authenticationManager.SignIn(claimsIdentity);

            // Rediriger vers l'url d'origine :
            if (Url.IsLocalUrl(ViewBag.ReturnUrl))
            {
                return(Redirect(ViewBag.ReturnUrl));
            }

            // Par défaut, rediriger vers la page d'accueil :
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        public object Post([FromBody] Objet_POST[] obj_from_javascript)
        {
            List <int> IDOBJETs = new List <int>();

            // Suppression des éventuelles doublons

            var obj_from_javascriptSD = obj_from_javascript
                                        .GroupBy(i => new { i.IDTYPEOBJETVUE, i.NOM })
                                        .Select(g => g.First());

            // Création des objets

            using (A_MAP_OFEntities context = new A_MAP_OFEntities())
            {
                // Pour chacun des objets uniques à créer

                foreach (Objet_POST mObjet_POST in obj_from_javascriptSD)
                {
                    // Recherche si l'objet est éventuellement déjà existant en base

                    IEnumerable <int> SelectQuery;

                    SelectQuery = (from r in context.OBJET
                                   where r.NOM == mObjet_POST.NOM &&
                                   r.IDTYPEOBJET == mObjet_POST.IDTYPEOBJETVUE
                                   select r.IDOBJET);

                    var resultat = Generic.Call_Read_FirstOrDefault <int>(SelectQuery);

                    // Si non

                    if ((int)resultat == 0)
                    {
                        // Création

                        OBJET mObjet = new OBJET();
                        mObjet.IDTYPEOBJET = mObjet_POST.IDTYPEOBJETVUE;
                        mObjet.NOM         = mObjet_POST.NOM;

                        context.OBJET.Add(mObjet);

                        // Enregistrement effectif

                        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'id

                        IDOBJETs.Add(mObjet.IDOBJET);
                    }    // Fin de test de préexistence de l'objet
                    else // si l'objet existe déjà, son id actuel est stocké
                    {
                        IDOBJETs.Add((int)resultat);
                    }
                } // Fin de boucle sur les objets
            }     // Fin using

            return(new { IDOBJETS = IDOBJETs });
        } // Fin de méthode