Example #1
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);
                }
            }
        }
Example #2
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);
                }
            }
        }
Example #3
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);
        }
Example #4
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);
                }
            }
        }