예제 #1
0
 public List <Movie> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Movie> movies = context.Movie.Select(x => new {
             x.Id_movie,
             x.Title,
             x.Synopsis,
             x.Rating,
             x.Duration,
             x.Id_type,
             x.Id_director,
             x.Id_image
         }).ToList()
                               .Select(x => new Movie()
         {
             Id_movie    = x.Id_movie,
             Title       = x.Title,
             Synopsis    = x.Synopsis,
             Rating      = x.Rating,
             Duration    = x.Duration,
             Id_type     = x.Id_type,
             Id_director = x.Id_director,
             Id_image    = x.Id_image
         }).ToList();
         return(movies);
     }
 }
예제 #2
0
 public Movie SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         Movie movie = context.Movie.Where(x => x.Id_movie == id)
                       .Select(x => new {
             x.Id_movie,
             x.Title,
             x.Synopsis,
             x.Rating,
             x.Duration,
             x.Id_type,
             x.Id_director,
             x.Id_image
         }).ToList()
                       .Select(x => new Movie()
         {
             Id_movie    = x.Id_movie,
             Title       = x.Title,
             Synopsis    = x.Synopsis,
             Rating      = x.Rating,
             Duration    = x.Duration,
             Id_type     = x.Id_type,
             Id_director = x.Id_director,
             Id_image    = x.Id_image
         }).DefaultIfEmpty().Single();
         return(movie);
     }
 }
예제 #3
0
 public int Create(Comment entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Comment.Add(entity);
         context.SaveChanges();
         return(entity.Id_comment);
     }
 }
예제 #4
0
 public void Delete(Director entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Director.Attach(entity);
         context.Director.Remove(entity);
         context.SaveChanges();
     }
 }
예제 #5
0
 public int Create(Image entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Image.Add(entity);
         context.SaveChanges();
         return(entity.Id_Image);
     }
 }
예제 #6
0
 public void Delete(Image entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Image.Attach(entity);
         context.Image.Remove(entity);
         context.SaveChanges();
     }
 }
예제 #7
0
 public void Modify(Image entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Image.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #8
0
 public int Create(Actor entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Actor.Add(entity);
         context.SaveChanges();
         return(entity.Id_actor);
     }
 }
예제 #9
0
 public int SelectIdByLogin(string Login)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         int id_user = context.User.Where(u => u.Login == Login)
                       .Select(x => x.Id_user)
                       .First();
         return(id_user);
     }
 }
예제 #10
0
 public double SelectRating(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         double rating = context.Comment
                         .Where(c => c.Id_movie == id)
                         .Select(x => x.Rating)
                         .DefaultIfEmpty()
                         .Average();
         return(rating);
     }
 }
예제 #11
0
 public void DeleteActors(Movie entity, List <int> Id_actors)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Movie.Attach(entity);
         context.Entry(entity).Collection("Actor").Load();
         foreach (int Id_actor in Id_actors)
         {
             entity.Actor.Remove(entity.Actor.FirstOrDefault(s => s.Id_actor == Id_actor));
         }
         context.SaveChanges();
     }
 }
예제 #12
0
 public bool CheckUserExist(string Login)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         int nbUser = context.User.Where(u => u.Login == Login).Count();
         if (nbUser != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #13
0
 public void AddActors(Movie entity, List <Actor> actors)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Movie.Attach(entity);
         foreach (Actor actor in actors)
         {
             context.Actor.Attach(actor);
             context.Entry(actor).State = System.Data.Entity.EntityState.Unchanged;
             entity.Actor.Add(actor);
         }
         context.Entry(entity).State = System.Data.Entity.EntityState.Unchanged;
         context.SaveChanges();
     }
 }
예제 #14
0
 public void Delete(Actor entity)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         context.Actor.Attach(entity);
         context.Entry(entity).Collection("Movie").Load();
         List <Movie> movies = entity.Movie.ToList();
         foreach (Movie movie in movies)
         {
             entity.Movie.Remove(movie);
         }
         context.Actor.Remove(entity);
         context.SaveChanges();
     }
 }
예제 #15
0
 public List <Image> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Image> images = context.Image.Select(x => new {
             x.Id_Image,
             x.URL
         }).ToList()
                               .Select(x => new Image()
         {
             Id_Image = x.Id_Image,
             URL      = x.URL
         }).ToList();
         return(images);
     }
 }
예제 #16
0
 public List <MovieType> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <MovieType> movieTypes = context.MovieType.Select(x => new {
             x.Id_type,
             x.Type
         }).ToList()
                                       .Select(x => new MovieType()
         {
             Id_type = x.Id_type,
             Type    = x.Type
         }).ToList();
         return(movieTypes);
     }
 }
예제 #17
0
 public Image SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         Image image = context.Image.Where(x => x.Id_Image == id)
                       .Select(x => new {
             x.Id_Image,
             x.URL
         }).ToList()
                       .Select(x => new Image()
         {
             Id_Image = x.Id_Image,
             URL      = x.URL
         }).DefaultIfEmpty().Single();
         return(image);
     }
 }
예제 #18
0
 public MovieType SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         MovieType movieType = context.MovieType.Where(x => x.Id_type == id)
                               .Select(x => new {
             x.Id_type,
             x.Type
         }).ToList()
                               .Select(x => new MovieType()
         {
             Id_type = x.Id_type,
             Type    = x.Type
         }).DefaultIfEmpty().Single();
         return(movieType);
     }
 }
예제 #19
0
 public List <User> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <User> users = context.User.Select(x => new {
             x.Id_user,
             x.Login,
             x.Password
         }).ToList()
                             .Select(x => new User()
         {
             Id_user  = x.Id_user,
             Login    = x.Login,
             Password = x.Password
         }).ToList();
         return(users);
     }
 }
예제 #20
0
 public List <Actor> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Actor> actors = context.Actor.Select(x => new {
             x.Id_actor,
             x.Firstname,
             x.Lastname
         }).ToList()
                               .Select(x => new Actor()
         {
             Id_actor  = x.Id_actor,
             Firstname = x.Firstname,
             Lastname  = x.Lastname
         }).ToList();
         return(actors);
     }
 }
예제 #21
0
 public User SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         User user = context.User.Where(x => x.Id_user == id)
                     .Select(x => new {
             x.Id_user,
             x.Login,
             x.Password
         }).ToList()
                     .Select(x => new User()
         {
             Id_user  = x.Id_user,
             Login    = x.Login,
             Password = x.Password
         }).DefaultIfEmpty().Single();
         return(user);
     }
 }
예제 #22
0
 public Actor SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         Actor actor = context.Actor.Where(x => x.Id_actor == id)
                       .Select(x => new {
             x.Id_actor,
             x.Firstname,
             x.Lastname
         }).ToList()
                       .Select(x => new Actor()
         {
             Id_actor  = x.Id_actor,
             Firstname = x.Firstname,
             Lastname  = x.Lastname
         }).DefaultIfEmpty().Single();
         return(actor);
     }
 }
예제 #23
0
 public List <Actor> SelectByMovie(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Actor> actors = context.Actor
                               .Where(a => a.Movie.Any(m => m.Id_movie == id))
                               .Select(x => new {
             x.Id_actor,
             x.Firstname,
             x.Lastname
         }).ToList()
                               .Select(x => new Actor()
         {
             Id_actor  = x.Id_actor,
             Firstname = x.Firstname,
             Lastname  = x.Lastname
         }).ToList();
         return(actors);
     }
 }
예제 #24
0
        public void Delete(Movie entity)
        {
            using (MovieLibraryEntities context = new MovieLibraryEntities())
            {
                context.Movie.Attach(entity);
                context.Entry(entity).Collection("Comment").Load();
                context.Entry(entity).Collection("Actor").Load();
                List <Comment> comments = entity.Comment.ToList();
                List <Actor>   actors   = entity.Actor.ToList();
                foreach (Comment comment in comments)
                {
                    context.Comment.Remove(comment);
                }

                foreach (Actor actor in actors)
                {
                    entity.Actor.Remove(actor);
                }
                context.Movie.Remove(entity);
                context.SaveChanges();
            }
        }
예제 #25
0
 public List <Comment> SelectAll()
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Comment> comments = context.Comment.Select(x => new {
             x.Id_comment,
             x.Id_movie,
             x.Id_user,
             x.Comment1,
             x.Rating
         }).ToList()
                                   .Select(x => new Comment()
         {
             Id_comment = x.Id_comment,
             Id_movie   = x.Id_movie,
             Id_user    = x.Id_user,
             Comment1   = x.Comment1,
             Rating     = x.Rating
         }).ToList();
         return(comments);
     }
 }
예제 #26
0
 public Comment SelectOne(int id)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         Comment comment = context.Comment.Where(x => x.Id_comment == id)
                           .Select(x => new {
             x.Id_comment,
             x.Id_movie,
             x.Id_user,
             x.Comment1,
             x.Rating
         }).ToList()
                           .Select(x => new Comment()
         {
             Id_comment = x.Id_comment,
             Id_movie   = x.Id_movie,
             Id_user    = x.Id_user,
             Comment1   = x.Comment1,
             Rating     = x.Rating
         }).DefaultIfEmpty().Single();
         return(comment);
     }
 }
예제 #27
0
 public List <Movie> SelectByMovieType(String movieType)
 {
     using (MovieLibraryEntities context = new MovieLibraryEntities())
     {
         List <Movie> movies = context.Movie
                               .Join(context.MovieType,
                                     m => m.Id_type,
                                     mt => mt.Id_type,
                                     (m, mt) => new { m, mt })
                               .Where(movietype => movietype.mt.Type.Contains(movieType))
                               .Select(movie => movie.m)
                               .ToList()
                               .Select(x => new {
             x.Id_movie,
             x.Title,
             x.Synopsis,
             x.Rating,
             x.Duration,
             x.Id_type,
             x.Id_director,
             x.Id_image
         }).ToList()
                               .Select(x => new Movie()
         {
             Id_movie    = x.Id_movie,
             Title       = x.Title,
             Synopsis    = x.Synopsis,
             Rating      = x.Rating,
             Duration    = x.Duration,
             Id_type     = x.Id_type,
             Id_director = x.Id_director,
             Id_image    = x.Id_image
         }).ToList();
         return(movies);
     }
 }