示例#1
0
        public void add(USER user)
        {
            try
            {
                Context.USERs.Add(user);
                Context.GROUPs.First(g => g.ID_GROUP == 1).USERs.Add(user);
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
            #if DEBUG
                throw new Exception("Impossible de ajouter l'utilisateur." + Environment.NewLine + ex.StackTrace);
            #else
            throw new Exception("Impossible de ajouter l'utilisateur.");

            #endif
            }
        }
示例#2
0
 public TokenModel Register(UserModel model)
 {
     if (model == null)
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     try
     {
         USER objBdd = new USER();
         objBdd.FIRST_NAME = model.FirstName;
         objBdd.LAST_NAME = model.Lastname;
         objBdd.ID_AGENCY = model.Agency.Id;
         objBdd.EMAIL = model.Email;
         objBdd.PASSWORD = model.Password;
         objBdd.DESCRIPTION = "";
         manager.add(objBdd);
         Guid guid = Guid.NewGuid();
         return new TokenModel(manager.addSession(objBdd.ID_USER));
     }
     catch
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
     throw new HttpResponseException(HttpStatusCode.Unauthorized);
 }
示例#3
0
 // POST api/values
 public HttpResponseMessage Post(UserModel model)
 {
     if (HttpContext.Current.Request.Headers["Authorization"] == null)
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
     USER objBdd = new USER();
     objBdd.FIRST_NAME = model.FirstName;
     objBdd.LAST_NAME = model.Lastname;
     objBdd.ID_AGENCY = model.Agency.Id;
     objBdd.EMAIL = model.Email;
     objBdd.PASSWORD = model.Password;
     objBdd.DESCRIPTION = model.Description;
     manager.add(objBdd);
     return new HttpResponseMessage()
     {
         Content = new JsonContent(new
         {
             Success = true, //error
             Message = "Success" //return exception
         })
     };
 }
示例#4
0
        public void remove(USER user)
        {
            try
            {
                Context.USERs.Remove(user);
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
            #if DEBUG
                throw new Exception("Impossible de supprimer l'utilisateur." + Environment.NewLine + ex.StackTrace);
            #else
            throw new Exception("Impossible de supprimer l'utilisateur.");

            #endif
            }
        }
示例#5
0
        public void modify(USER user)
        {
            try
            {
                Context.USERs.Attach(user);
                Context.Entry(user).State = EntityState.Modified;
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
            #if DEBUG
                throw new Exception("Impossible de modifier l'utilisateur." + Environment.NewLine + ex.StackTrace);
            #else
            throw new Exception("Impossible de modifier l'utilisateur.");

            #endif
            }
        }