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); } }
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); } }
public int Create(Comment entity) { using (MovieLibraryEntities context = new MovieLibraryEntities()) { context.Comment.Add(entity); context.SaveChanges(); return(entity.Id_comment); } }
public void Delete(Director entity) { using (MovieLibraryEntities context = new MovieLibraryEntities()) { context.Director.Attach(entity); context.Director.Remove(entity); context.SaveChanges(); } }
public int Create(Image entity) { using (MovieLibraryEntities context = new MovieLibraryEntities()) { context.Image.Add(entity); context.SaveChanges(); return(entity.Id_Image); } }
public void Delete(Image entity) { using (MovieLibraryEntities context = new MovieLibraryEntities()) { context.Image.Attach(entity); context.Image.Remove(entity); context.SaveChanges(); } }
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(); } }
public int Create(Actor entity) { using (MovieLibraryEntities context = new MovieLibraryEntities()) { context.Actor.Add(entity); context.SaveChanges(); return(entity.Id_actor); } }
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); } }
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); } }
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(); } }
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); } } }
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(); } }
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(); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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(); } }
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); } }
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); } }
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); } }