Example #1
0
 public ActionResult Add(string token = "")
 {
     try
     {
         if (!ServiceToken.Instance.IsValidToken(token))
             throw new Exception("Token non valide");
         string nom = Request.Form.Get("Nom");
         if(string.IsNullOrEmpty(nom))
             throw new Exception("Nom du groupe obligatoire");
         string description = Request.Form.Get("Description");
         Groupe groupe = new Groupe();
         groupe.Nom = nom;
         groupe.Description = description;
         if (ServiceGroupe.Instance.Add(groupe))
             return Json(groupe);
         else
             throw new Exception("Erreur d'enregistrement du groupe");
     }
     catch (Exception e)
     {
         var dict = new Dictionary<object, object>();
         dict.Add("Error", e.Message);
         return Json(dict);
     }
 }
Example #2
0
        public bool Add(Groupe group)
        {
            try
            {
                using (APIEntities manager = new APIEntities())
                {
                    manager.Groupe.Add(group);
                    manager.SaveChanges();
                    return true;
                }
            }
            catch
            {

                return false;
            }
        }
Example #3
0
        public ActionResult Update(string token = "")
        {
            var dict = new Dictionary<object, object>();
            try
            {
                if (!ServiceToken.Instance.IsValidToken(token))
                    throw new Exception("Token non valide");
                string GroupId = Request.Form.Get("GroupId");
                int Id = 0;
                if (!int.TryParse(GroupId, out Id))
                    throw new Exception("Group Id non accepté");
                string nom = Request.Form.Get("Nom");
                string description = Request.Form.Get("Description");
                Groupe groupe = new Groupe();
                groupe.Id = Id;
                groupe.Nom = nom;
                groupe.Description = description;
                if (ServiceGroupe.Instance.Update(groupe))
                    return Json(groupe);
                else
                    throw new Exception("Erreur d'enregistrement du groupe");
            }
            catch (Exception e)
            {

                dict.Add("Error", e.Message);
                return Json(dict);
            }
        }
Example #4
0
        public bool Update(Groupe groupe)
        {
            try
            {
                using (APIEntities manager = new APIEntities())
                {
                    Groupe groupeE = manager.Groupe.Where(x => x.Id == groupe.Id).First();
                    manager.Groupe.Attach(groupeE);
                    manager.Entry(groupeE).State = System.Data.Entity.EntityState.Modified;
                    manager.SaveChanges();
                    return true;
                }
            }
            catch
            {

                return false;
            }
        }