示例#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);
     }
 }