Exemplo n.º 1
0
        public User createUserDao(String _login, String _password)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                //Create entity to insert and set his properties
                var newUser = new User()
                {
                    login    = _login,
                    password = _password,
                };


                db.Entry(newUser).State = System.Data.Entity.EntityState.Added; //Insert property in the DB
                int res = db.SaveChanges();                                     //Save the modification to th DB if the save is successful the function return "true"

                if (res > 0)
                {
                    MessageBox.Show("User successfuly created");
                    return(newUser);
                }
                else
                {
                    MessageBox.Show("Error cant create user");
                    return(newUser);
                }
            }
        }
Exemplo n.º 2
0
        public int updateMovieDao(int movieId, string movieTitle, string movieKind, string movieSynopsis)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var movieSelected = db.MovieSet.Where(m => m.Id == movieId).First();//Search the movie to update in db

                //set the property of the movie
                movieSelected.title    = movieTitle;
                movieSelected.kind     = movieKind;
                movieSelected.synopsis = movieSynopsis;

                int res = db.SaveChanges();

                if (res > 0)
                {
                    MessageBox.Show("Movie update successful");
                    return(res);
                }
                else
                {
                    MessageBox.Show("Error cant update movie");
                    return(res);
                }
            }
        }
Exemplo n.º 3
0
        public bool updateUserDao(int userId, String Login, String Password)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var userToUpdate = db.UserSet.Where(u => u.Id == userId).First();//Search the movie to update in db


                userToUpdate.login    = Login;
                userToUpdate.password = Password;

                db.Entry(userToUpdate).State = System.Data.Entity.EntityState.Modified;


                int res = db.SaveChanges();

                if (res > 0)
                {
                    MessageBox.Show("User data update successful");
                    return(true);
                }
                else
                {
                    MessageBox.Show("User data can't be updated, try again");
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
        public int createMovieDao(string _title, string _kind, string _synopsis)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                //Create entity to insert and set his properties
                var myMovie = new Movie()
                {
                    title    = _title,
                    kind     = _kind,
                    synopsis = _synopsis,
                };


                db.Entry(myMovie).State = System.Data.Entity.EntityState.Added; //Insert property in the DB
                int res = db.SaveChanges();                                     //Save the modification to th DB if the save is successful the function return "true"

                if (res > 0)
                {
                    MessageBox.Show("Movie creation successful");
                    return(res);
                }
                else
                {
                    MessageBox.Show("Error cant create movie");
                    return(res);
                }
            }
        }
Exemplo n.º 5
0
        public bool isUserExists(int id)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var user = (from u in db.UserSet
                            where u.Id == id
                            select u).FirstOrDefault <User>();
                return(user != null);
            }
        }
Exemplo n.º 6
0
        public Movie getMovie(int movieId)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var movieToGet = (from m in db.MovieSet
                                  where m.Id == movieId
                                  select m).First();

                return(movieToGet);
            }
        }
Exemplo n.º 7
0
        public List <Movie> getMoviesDao()
        {
            //DataModelContainer container the string to reference/Target wich DB to used(ctrl+click or alt+click to see the content of the class)
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var movies = (from m in db.MovieSet
                              select m).ToList();

                return(movies);
            }
        }
Exemplo n.º 8
0
        public bool deleteMovieDao(int movieId)
        {
            using (var db = new DataModelContainer())
            {
                var movieToDelete = new Movie {
                    Id = movieId
                };

                db.Entry(movieToDelete).State = System.Data.Entity.EntityState.Deleted;//Delete element in DB according to the ID

                db.SaveChanges();
                //db.Database.Connection.Close();
            }
            return(true);
        }
Exemplo n.º 9
0
        public User getUserDao(int userID)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var user = (from u in db.UserSet
                            where u.Id == userID
                            select u).FirstOrDefault <User>();

                if (user != null)
                {
                    MessageBox.Show("the user exist" + user.login);
                }


                return(user);
            }
        }
Exemplo n.º 10
0
        public User loginDao(string login, string password)
        {
            //DataModelContainer container the string to reference/Target wich DB to used(ctrl+click or alt+click to see the content of the class)
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var user = (from u in db.UserSet
                            where u.login == login && u.password == password
                            select u).FirstOrDefault <User>();//Récupère le premier user correspondant o critère de recherche

                if (user != null)
                {
                    MessageBox.Show("Welcome " + user.login);
                }

                return(user);
            }
        }
Exemplo n.º 11
0
        public bool deleteUserDao(User userTodelete)
        {
            using (var db = new DataModelContainer())
            {
                db.Database.Connection.Open();

                var user = (from u in db.UserSet
                            where u.Id == userTodelete.Id
                            select u).FirstOrDefault <User>();


                if (user == null)
                {
                    return(false);
                }
                else
                {
                    db.Entry(user).State = System.Data.Entity.EntityState.Deleted;//Delete element in DB according to
                    db.SaveChanges();
                    return(true);
                }
            }
        }