Exemplo n.º 1
0
        public List <Movie> FindMoviesOfUser(int idUser)
        {
            List <Movie> movies = new List <Movie>();

            try
            {
                DbMovieNetEntities entities = new DbMovieNetEntities();

                var             query = (from n in entities.MovieSets where n.UserSet.Id == idUser select n).ToList();
                List <MovieSet> list  = query.ToList();

                foreach (MovieSet mv in list)
                {
                    movies.Add(new Movie
                    {
                        IdGetSet       = mv.Id,
                        TitleGetSet    = mv.Title,
                        DurationGetSet = mv.Duration,
                        GenreGetSet    = mv.Genre,
                        SummaryGetSet  = mv.Summary,
                        ImageGetSet    = mv.Image
                    });;
                }
            }
            catch (SqlException ex)
            {
                throw new FaultException("Erreur Finding note of user " + ex.Errors);
            }

            return(movies);
        }
Exemplo n.º 2
0
        public bool CreateMovie(string _title, string _duration, string _genre, string _summary, string _image, int _UserSet_id)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    entities.MovieSets.Add(new MovieSet()
                    {
                        Title    = _title,
                        Duration = _duration,
                        Genre    = _genre,
                        Summary  = _summary,
                        Image    = _image,
                        User_Id  = _UserSet_id
                    });

                    entities.SaveChanges();
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool UpdateUser(int _Id, string _title, string _duration, string _genre, string _summary, string _image)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    MovieSet MovieUpdate = null;
                    MovieUpdate = (from mv in entities.MovieSets where mv.Id == _Id select mv).FirstOrDefault();

                    if (MovieUpdate == null)
                    {
                        return(false);
                    }
                    else
                    {
                        MovieUpdate.Title    = _title;
                        MovieUpdate.Duration = _duration;
                        MovieUpdate.Genre    = _genre;
                        MovieUpdate.Summary  = _summary;
                        MovieUpdate.Image    = _image;

                        entities.SaveChanges();
                    }
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
        public IReadOnlyCollection <Note> FindNotesOfUser(int idUser)
        {
            IReadOnlyCollection <Note> FindNoteUserCollection = default(IReadOnlyCollection <Note>);
            IList <Note> FindNoteUserList      = new List <Note>();
            NoteSet      resultFindUserNoteSet = null;

            try
            {
                using (DbMovieNetEntities entities = new DbMovieNetEntities())
                {
                    resultFindUserNoteSet = (from nt in entities.NoteSets where nt.UserSet.Id == idUser select nt).FirstOrDefault();
                }

                FindNoteUserList.Add(new Note
                {
                    ScoreGetSet    = resultFindUserNoteSet.Score,
                    CommentGetSet  = resultFindUserNoteSet.Comment,
                    Movie_idGetSet = resultFindUserNoteSet.Movie_Id,
                    User_idGetSet  = resultFindUserNoteSet.User_Id
                });
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(FindNoteUserCollection = new ReadOnlyCollection <Note>(FindNoteUserList));
        }
Exemplo n.º 5
0
        public ObservableCollection <Movie> FindMovieByTitle(string titleSet)
        {
            ObservableCollection <Movie> MovieCollec = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    MovieCollec = new ObservableCollection <Movie>(entities.MovieSets.Where(movie => movie.Title.Contains(titleSet)).Select(
                                                                       movie => new Movie()
                    {
                        IdGetSet       = movie.Id,
                        TitleGetSet    = movie.Title,
                        DurationGetSet = movie.Duration,
                        GenreGetSet    = movie.Genre,
                        SummaryGetSet  = movie.Summary,
                        ImageGetSet    = movie.Image,
                    }));
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(MovieCollec);
        }
Exemplo n.º 6
0
        public User LoginUser(string _Login, string _Password)
        {
            UserSet userset = null;
            User    user    = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    userset = (from u in entities.UserSets where u.Login == _Login && u.Password == _Password select u).FirstOrDefault();

                    if (userset == null)
                    {
                        return(null);
                    }
                }
                user = new User
                {
                    LoginGetSet    = userset.Login,
                    PasswordGetSet = userset.Password
                };
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(user);
        }
Exemplo n.º 7
0
        public ObservableCollection <User> GetUsersFind(int id)
        {
            ObservableCollection <User> searchUser = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    searchUser = new ObservableCollection <User>(entities.UserSets.Where(u => u.Id == id).Select(

                                                                     user => new User()
                    {
                        IdGetSet        = user.Id,
                        FirstnameGetSet = user.Firstname,
                        LastnameGetSet  = user.Lastname,
                        LoginGetSet     = user.Login,
                        PasswordGetSet  = user.Password
                    }));;
                }

                return(searchUser);
            }
            catch (SqlException ex)
            {
                throw new FaultException("Erreur GetUsers: " + ex.Errors);
            }
        }
Exemplo n.º 8
0
        public ObservableCollection <User> GetUsersFindByLogin(string login)
        {
            ObservableCollection <User> searchUser = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    searchUser = new ObservableCollection <User>(entities.UserSets.Where(u => u.Login == login).Select(

                                                                     user => new User()
                    {
                        IdGetSet        = user.Id,
                        FirstnameGetSet = user.Firstname,
                        LastnameGetSet  = user.Lastname,
                        LoginGetSet     = user.Login,
                        PasswordGetSet  = user.Password
                    }));
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(searchUser);

            #endregion
        }
        public IReadOnlyCollection <Note> GetNote(int id)
        {
            IReadOnlyCollection <Note> NoteCollection = default(IReadOnlyCollection <Note>);
            IList <Note> NoteList      = new List <Note>();
            NoteSet      resultNoteSet = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    resultNoteSet = entities.NoteSets.Where(note => note.Id == id).FirstOrDefault();
                }


                NoteList.Add(new Note
                {
                    ScoreGetSet    = resultNoteSet.Score,
                    CommentGetSet  = resultNoteSet.Comment,
                    Movie_idGetSet = resultNoteSet.Movie_Id
                });
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(NoteCollection = new ReadOnlyCollection <Note>(NoteList));
        }
Exemplo n.º 10
0
        public bool UpdateUser(string _nom, string _prenom, string _login, string _password)
        {
            try
            {
                using (DbMovieNetEntities entities = new DbMovieNetEntities())
                {
                    UserSet UserUpdate = null;
                    UserUpdate = (from u in entities.UserSets where u.Login == _login select u).FirstOrDefault();



                    if (UserUpdate == null)
                    {
                        return(false);
                    }
                    else
                    {
                        UserUpdate.Firstname = _nom;
                        UserUpdate.Lastname  = _prenom;
                        UserUpdate.Login     = _login;
                        UserUpdate.Password  = _password;

                        entities.SaveChanges();
                    }
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
        public IReadOnlyCollection <Note> GetAllNote()
        {
            IReadOnlyCollection <Note> movieCollection = default(IReadOnlyCollection <Note>);
            IList <Note> NoteList      = new List <Note>();
            var          resultNoteSet = (dynamic)null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    resultNoteSet = (from nt in entities.NoteSets select nt).ToList();
                }


                foreach (NoteSet mv in resultNoteSet)
                {
                    NoteList.Add(new Note
                    {
                        ScoreGetSet    = mv.Score,
                        CommentGetSet  = mv.Comment,
                        Movie_idGetSet = mv.Movie_Id
                    });
                }

                movieCollection = new ReadOnlyCollection <Note>(NoteList);
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(movieCollection);
        }
        public bool UpdateNote(Note noteSet)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    var NoteUpdate = entities.NoteSets.FirstOrDefault(movie =>
                                                                      movie.Score == noteSet.ScoreGetSet &&
                                                                      movie.Comment == noteSet.CommentGetSet);

                    if (NoteUpdate != null)
                    {
                        NoteUpdate.Score   = noteSet.ScoreGetSet;
                        NoteUpdate.Comment = noteSet.CommentGetSet;

                        entities.SaveChanges();
                    }
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
Exemplo n.º 13
0
        public IReadOnlyCollection <Movie> FindMovieByGenre(string genreSet)
        {
            IReadOnlyCollection <Movie> movieCollectGenre = default(IReadOnlyCollection <Movie>);
            IList <Movie>    movieList      = new List <Movie>();
            IList <MovieSet> resultMovieSet = default(IList <MovieSet>);

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    resultMovieSet = entities.MovieSets.Where(movie => movie.Genre.Contains(genreSet)).ToList();
                }

                foreach (MovieSet mv in resultMovieSet)
                {
                    movieList.Add(new Movie
                    {
                        TitleGetSet    = mv.Title,
                        DurationGetSet = mv.Duration,
                        GenreGetSet    = mv.Genre,
                        SummaryGetSet  = mv.Summary,
                        ImageGetSet    = mv.Image
                    });
                }

                movieCollectGenre = new ReadOnlyCollection <Movie>(movieList);
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(movieCollectGenre);
        }
Exemplo n.º 14
0
        public ObservableCollection <User> GetUsers()
        {
            ObservableCollection <User> UserCollec = null;

            using (var entities = new DbMovieNetEntities())
            {
                UserCollec = new ObservableCollection <User>(entities.UserSets.Select(
                                                                 user => new User()
                {
                    FirstnameGetSet = user.Firstname,
                    LastnameGetSet  = user.Lastname,
                    LoginGetSet     = user.Login,
                    PasswordGetSet  = user.Password
                }));
            }
            return(UserCollec);
        }
Exemplo n.º 15
0
        public bool DeleteUser(User user)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    var Userdelete = entities.UserSets.Where(userSet => userSet.Login == user.LoginGetSet).ToArray();

                    entities.UserSets.RemoveRange(entities: Userdelete);
                    entities.SaveChanges();
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
Exemplo n.º 16
0
        /*
         #region GetMovieID
         *
         * public IReadOnlyCollection<Movie> GetMovie(int idSet)
         * {
         *  IReadOnlyCollection<Movie> movieCollection = default(IReadOnlyCollection<Movie>);
         *  IList<Movie> movieList = new List<Movie>();
         *  MovieSet resultMovieSet = null;
         *
         *  try
         *  {
         *      using (var entities = new DbMovieNetEntities())
         *      {
         *          resultMovieSet = entities.MovieSets.Where(movie => movie.Id == idSet).FirstOrDefault();
         *      }
         *
         *
         *          movieList.Add(new Movie
         *          {
         *              TitleGetSet = resultMovieSet.Title,
         *              DurationGetSet = resultMovieSet.Duration,
         *              GenreGetSet = resultMovieSet.Genre,
         *              SummaryGetSet = resultMovieSet.Summary
         *
         *          });
         *
         *
         *      movieCollection = new ReadOnlyCollection<Movie>(movieList);
         *
         *  }
         *  catch (SqlException ex)
         *  {
         *      NewMethodException(ex);
         *  }
         *
         *  return movieCollection;
         * }
         #endregion
         */
        #region Movie by Id
        public ObservableCollection <Movie> GetAllMoviesById(int idSet)
        {
            ObservableCollection <Movie> MovieCollec = null;

            using (var entities = new DbMovieNetEntities())
            {
                MovieCollec = new ObservableCollection <Movie>(entities.MovieSets.Where(movie => movie.Id == idSet).Select(
                                                                   movie => new Movie()
                {
                    TitleGetSet      = movie.Title,
                    DurationGetSet   = movie.Duration,
                    GenreGetSet      = movie.Genre,
                    SummaryGetSet    = movie.Summary,
                    ImageGetSet      = movie.Image,
                    UserSet_idGetSet = movie.UserSet.Id
                }));
            }
            return(MovieCollec);
        }
        public bool DeleteNote(Note note)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    var Notedelete = entities.NoteSets.Where(nt => nt.Id == note.IdGetSet).ToArray();

                    entities.NoteSets.RemoveRange(Notedelete);
                    entities.SaveChanges();
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
Exemplo n.º 18
0
        public bool DeleteMovie(int idSet)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    var Moviedelete = entities.MovieSets.Where(movie => movie.Id == idSet).ToArray();

                    entities.MovieSets.RemoveRange(Moviedelete);
                    entities.SaveChanges();
                }
            }

            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
Exemplo n.º 19
0
        public bool CreateUser(string _Firstname, string _Lastname, string _Login, string _Password)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    entities.UserSets.Add(new UserSet()
                    {
                        Firstname = _Firstname,
                        Lastname  = _Lastname,
                        Login     = _Login,
                        Password  = _Password
                    });

                    entities.SaveChanges();
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
        public bool CreateNote(int _note, string _comment, int _idUser, int _idMovie)
        {
            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    entities.NoteSets.Add(new NoteSet()
                    {
                        Score    = _note,
                        Comment  = _comment,
                        Movie_Id = _idMovie,
                        User_Id  = _idUser
                    });

                    entities.SaveChanges();
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }
            return(true);
        }
        public ObservableCollection <Note> FindNotesOfMovie(int idMovie)
        {
            ObservableCollection <Note> FindNoteList = null;

            try
            {
                using (var entities = new DbMovieNetEntities())
                {
                    FindNoteList = new ObservableCollection <Note>(entities.NoteSets.Where(note => note.Movie_Id == idMovie).Select(
                                                                       note => new Note()
                    {
                        ScoreGetSet    = note.Score,
                        CommentGetSet  = note.Comment,
                        Movie_idGetSet = note.Movie_Id
                    }).ToList());
                }
            }
            catch (SqlException ex)
            {
                NewMethodException(ex);
            }

            return(FindNoteList);
        }