예제 #1
0
        public bool EditUser(int id, string username, string email)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                //Find a user in the collection using Linq to SQL with a lambda expression.
                User user = entity.users.FirstOrDefault(x => x.id == id);

                user.username = username;
                user.email    = email;

                try
                {
                    entity.users.Attach(user);

                    var entry = entity.Entry(user);
                    entry.Property(u => u.email).IsModified    = true;
                    entry.Property(u => u.username).IsModified = true;
                    entity.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
예제 #2
0
        public bool EditUser(int id, string username, string email)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                //Find a user in the collection using Linq to SQL with a lambda expression.
                User user = entity.users.FirstOrDefault(x => x.id == id);

                user.username = username;
                user.email = email;

                try
                {
                    entity.users.Attach(user);

                    var entry = entity.Entry(user);
                    entry.Property(u => u.email).IsModified = true;
                    entry.Property(u => u.username).IsModified = true;
                    entity.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                }
            }
        }
예제 #3
0
 public void PopulateTable(List <User> users)
 {
     using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
     {
         foreach (var user in users)
         {
             CreateUser(user.username, user.email);
         }
     }
 }
예제 #4
0
 public List<User> GetAllUsers()
 {
     using(school_windowsformsEntities1 entity = new school_windowsformsEntities1())
     {
         List<User> userList = new List<User>();
         foreach (User u in entity.users)
         {
             userList.Add(u);
         }
         return userList;
     }
 }
예제 #5
0
        public void TruncateTable()
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                var allUsers = GetAllUsers();

                foreach (var user in allUsers)
                {
                    DeleteUser(user.id);
                }
            }
        }
예제 #6
0
 public List <User> GetAllUsers()
 {
     using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
     {
         List <User> userList = new List <User>();
         foreach (User u in entity.users)
         {
             userList.Add(u);
         }
         return(userList);
     }
 }
예제 #7
0
        public bool DeleteUser(int id)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                //Find a user in the collection using Linq to SQL with a lambda expression.
                User user = entity.users.FirstOrDefault(x => x.id == id);

                try
                {
                    entity.users.Remove(user);
                    entity.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                }
            }
        }
예제 #8
0
        public bool DeleteUser(int id)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                //Find a user in the collection using Linq to SQL with a lambda expression.
                User user = entity.users.FirstOrDefault(x => x.id == id);

                try
                {
                    entity.users.Remove(user);
                    entity.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
예제 #9
0
        public bool CreateUser(string username, string email)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                User user = new User();
                user.username = username;
                user.email = email;

                try
                {
                    entity.users.Add(user);
                    entity.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    return false;
                }
            }
        }
예제 #10
0
        public bool CreateUser(string username, string email)
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                User user = new User();
                user.username = username;
                user.email    = email;

                try
                {
                    entity.users.Add(user);
                    entity.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
예제 #11
0
 public void PopulateTable(List<User> users)
 {
     using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
     {
         foreach (var user in users)
         {
             CreateUser(user.username, user.email);
         }
     }
 }
예제 #12
0
 public bool IsDatabaseAvailable()
 {
     school_windowsformsEntities1 entity = new school_windowsformsEntities1();
     return entity.Database.Exists();
 }
예제 #13
0
        public void TruncateTable()
        {
            using (school_windowsformsEntities1 entity = new school_windowsformsEntities1())
            {
                var allUsers = GetAllUsers();

                foreach (var user in allUsers)
                {
                    DeleteUser(user.id);
                }
            }
        }
예제 #14
0
        public bool IsDatabaseAvailable()
        {
            school_windowsformsEntities1 entity = new school_windowsformsEntities1();

            return(entity.Database.Exists());
        }