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;
                }
            }
        }
Esempio n. 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);
                }
            }
        }
        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;
                }
            }
        }
Esempio n. 4
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);
                }
            }
        }
        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;
                }
            }
        }
Esempio n. 6
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);
                }
            }
        }