示例#1
0
 public void UpdateUser(User editedUser)
 {
     try
     {
         using (var context = new JsonContext())
         {
             context.ObjUser.AddOrUpdate(editedUser);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         //Log error
     }
 }
示例#2
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);
        }
示例#3
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
     }
 }