Example #1
0
 public User FindUser(int id)
 {
     try
     {
         using (var context = new JsonContext())
         {
             return(context.ObjUser.Find(id));
         }
     }
     catch (Exception)
     {
         //Log error
         return(null);
     }
 }
Example #2
0
 public void UpdateUser(User editedUser)
 {
     try
     {
         using (var context = new JsonContext())
         {
             context.ObjUser.AddOrUpdate(editedUser);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         //Log error
     }
 }
Example #3
0
 public List <User> GetAllUsers()
 {
     try
     {
         using (var context = new JsonContext())
         {
             return(context.ObjUser.ToList());
         }
     }
     catch (Exception)
     {
         //Log error
         return(null);
     }
 }
Example #4
0
        public User CreateUser(User newUser)
        {
            try
            {
                using (var context = new JsonContext())
                {
                    context.ObjUser.Add(newUser);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                //Log error
                newUser = null;
            }

            return(newUser);
        }
Example #5
0
 public void DeleteUser(int id)
 {
     try
     {
         using (var context = new JsonContext())
         {
             var user = context.ObjUser.Find(id);         //fetching the user with Id
             if (user != null)
             {
                 context.ObjUser.Remove(user);              //deleting from db
                 context.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
         //Log error
     }
 }