public Cinema GetCinemaById(int cinemaId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Cinemas.Where(b => b.Id == cinemaId && b.Deleted == false).FirstOrDefault()); } }
public List <Critic> AllCritics() { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Critics.Where(s => s.Deleted == false).ToList()); } }
public bool DeleteDirector(int directorId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var director = dbContext.Directors.Where(b => b.Id == directorId && b.Deleted == false).FirstOrDefault(); if (director != null) { director.Deleted = true; dbContext.Entry(director).State = EntityState.Modified; dbContext.SaveChanges(); DALMovie dALMovie = new DALMovie(); //kad brisemo rezisera, nece postojati vise ni filmovi koji su vezani za tog rezisera var directedMovies = dbContext.Movies.Where(m => m.Director_Id == directorId && m.Deleted == false).ToList(); if (directedMovies != null) { directedMovies.ForEach(d => { dALMovie.DeleteMovie(d.Id); }); } return(true); } else { return(false); } } }
public void UpdateDistributor(Distributor distributor) { try { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var fest = dbContext.Distributors.Where(b => b.Id == distributor.Id).FirstOrDefault(); if (fest != null) { fest.Name = distributor.Name; fest.Deleted = distributor.Deleted; dbContext.Entry(fest).State = EntityState.Modified; dbContext.SaveChanges(); } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public List <Movie> GetMoviesByGenre(int genreId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { DALGenre dALGenre = new DALGenre(); List <Movie> movies = new List <Movie>(); var genre = dALGenre.GetGenreById(genreId); if (genre != null) { foreach (var movie in AllMovies()) { foreach (var genree in movie.Genres.Where(g => !g.Deleted).ToList()) { if (genree.Id == genreId) { movies.Add(movie); } } } } return(movies); } }
public void AddDistributor(Distributor distributor) { try { if (distributor.Id == 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var dis = dbContext.Distributors.Where(b => b.Id == distributor.Id).FirstOrDefault(); if (dis == null) { Distributor newDis = new Distributor { Name = distributor.Name, Deleted = false }; dbContext.Distributors.Add(newDis); dbContext.SaveChanges(); } } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public List <Movie> SearchMovies(string searchText) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { try { var movies = dbContext.SearchMovieByTitle(searchText).ToList(); if (movies.Count > 0) { List <Movie> findedMovies = new List <Movie>(); movies.ForEach(m => { findedMovies.Add(GetMovieById(m.Id)); }); return(findedMovies); } else { return(null); } } catch (Exception e) { MessageBox.Show(e.Message); return(null); } } }
public void UpdateMovie(Movie movie) { try { if (movie.Id != 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var ex_movie = dbContext.Movies.Where(b => b.Id == movie.Id).FirstOrDefault(); if (ex_movie != null) { ex_movie.Title = movie.Title; ex_movie.Duration = movie.Duration; ex_movie.Desctiprion = movie.Desctiprion; ex_movie.Distributor_Id = movie.Distributor_Id; ex_movie.Director_Id = movie.Director_Id; ex_movie.MetaScore = movie.MetaScore; ex_movie.Image = movie.Image; ex_movie.Deleted = movie.Deleted; dbContext.Entry(ex_movie).State = EntityState.Modified; dbContext.SaveChanges(); } } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public void AddPlace(Place place) { try { if (place.Id == 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var dis = dbContext.Places.Where(b => b.Id == place.Id).FirstOrDefault(); if (dis == null) { Place newPlace = new Place { Name = place.Name, Deleted = false }; dbContext.Places.Add(newPlace); dbContext.SaveChanges(); } } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public Award GetAwardById(int awardId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Awards.Where(b => b.Id == awardId && b.Deleted == false).FirstOrDefault()); } }
public Critic GetCriticById(int criticId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Critics.Where(b => b.Id == criticId && b.Deleted == false).FirstOrDefault()); } }
public void AddMovieFestivalProcedure(int festivalId, int movieId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { dbContext.AddMovieFestival(festivalId, movieId); } }
public void AddGenre(Genre genre) { try { if (genre.Id == 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var fest = dbContext.Genres.Where(b => b.Id == genre.Id).FirstOrDefault(); if (fest == null) { Genre newZanr = new Genre { Name = genre.Name, Deleted = false }; dbContext.Genres.Add(newZanr); dbContext.SaveChanges(); } } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public void AddBelongToGenreProcedure(int genreId, int movieId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { dbContext.AddBelongsToGenre(genreId, movieId); } }
public Genre GetGenreById(int genreId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Genres.Where(b => b.Id == genreId && b.Deleted == false).FirstOrDefault()); } }
public Director GetDirectorById(int directorId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Directors.Where(b => b.Id == directorId && b.Deleted == false).FirstOrDefault()); } }
public List <Genre> AllGenres() { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Genres.Where(s => s.Deleted == false).ToList()); } }
public void AddActsProcedure(int actorId, int movieId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { dbContext.AddActs(actorId, movieId); } }
public bool DeleteReview(int reviewId) { try { using (IMDBEntities7 dbContext = new IMDBEntities7(true)) { var review = dbContext.Reviews.Where(b => b.Id == reviewId && b.Deleted == false).FirstOrDefault(); if (review != null) { review.Deleted = true; dbContext.Entry(review).State = EntityState.Modified; dbContext.SaveChanges(); var movies = dbContext.Movies.Where(c => c.Deleted == false).ToList(); movies.ForEach(c => { c.Reviews.Remove(review); }); // dbContext.SaveChanges(); return(true); } else { return(false); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); return(false); } }
public List <Director> AllDirectors() { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Directors.Where(s => s.Deleted == false).ToList()); } }
public Place GetPlaceById(int placeId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Places.Where(b => b.Id == placeId && b.Deleted == false).FirstOrDefault()); } }
public void UpdateGenre(Genre genre) { try { if (genre.Id != 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var fest = dbContext.Genres.Where(b => b.Id == genre.Id).FirstOrDefault(); if (fest != null) { fest.Deleted = genre.Deleted; fest.Name = genre.Name; dbContext.Entry(fest).State = EntityState.Modified; dbContext.SaveChanges(); } } } } catch (SqlException ex) { System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); } }
public void AddActor(Actor actor) { if (actor.Id == 0) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { var fest = dbContext.Actors.Where(b => b.Id == actor.Id && b.Deleted == false).FirstOrDefault(); if (fest == null) { Actor newActor = new Actor { Name = actor.Name, Surname = actor.Surname, Image = actor.Image, Birthday = actor.Birthday, BirthPlace = actor.BirthPlace, Country = actor.Country, Deleted = false }; dbContext.Actors.Add(newActor); dbContext.SaveChanges(); } } } }
public bool DeleteFestival(int festivalId) { try { using (IMDBEntities7 dbContext = new IMDBEntities7(true)) { var festival = dbContext.Festivals.Where(b => b.Id == festivalId && b.Deleted == false).FirstOrDefault(); if (festival != null) { festival.Deleted = true; dbContext.Entry(festival).State = EntityState.Modified; dbContext.SaveChanges(); //brisemo iz veze sa nagradom var festivalAward = dbContext.AwardFestivals.Where(s => s.Festival_Id == festivalId && s.Deleted == false).ToList(); festivalAward.ForEach(s => { s.Deleted = true; dbContext.Entry(s).State = EntityState.Modified; dbContext.SaveChanges(); }); //brisemo iz veze sa nagradom i filmom var movieAwarded = dbContext.MovieFestivalAwards .Where(s => s.AwardFestival_Festival_Id == festivalId && s.Deleted == false).ToList(); movieAwarded.ForEach(s => { s.Deleted = true; dbContext.Entry(s).State = EntityState.Modified; dbContext.SaveChanges(); }); //brisemo festival iz filmova na kojima su ucestvovali List <Movie> movies = new List <Movie>(); foreach (var movie in dbContext.Movies) { movie.Festivals.ToList().ForEach(m => { if (m.Id == festivalId) { movies.Add(movie); } }); } movies.ForEach(a => { a.Festivals.Remove(festival); }); dbContext.SaveChanges(); } return(true); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message); return(false); } }
public List <AwardFestival> AllAwardsForFestival(int festivalId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.AwardFestivals.Where(s => s.Deleted == false && s.Festival_Id == festivalId) .Include(f => f.MovieFestivalAwards).ToList()); } }
public List <Award> AllAwards() { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Awards.Where(s => s.Deleted == false) .Include(s => s.AwardFestivals).ToList()); } }
public List <AwardFestival> GetAwardForFestival(int festivalId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.AwardFestivals.Where(b => b.Festival_Id == festivalId && b.Deleted == false) .Include(b => b.Award).ToList()); } }
public Review GetReviewById(int reviewId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Reviews .Where(b => b.Id == reviewId && b.Deleted == false) .Include(b => b.Critic).FirstOrDefault()); } }
public List <ShowsMovie> GetMoviesInCinema(int cinemaId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.ShowsMovies.Where(b => b.Cinema_Id == cinemaId && b.Deleted == false) .Include(m => m.Movie) .ToList()); } }
public List <Review> GetNotApprovedReviewsForMovie(int reviewId, int movieId) { using (IMDBEntities7 dbContext = new IMDBEntities7()) { return(dbContext.Reviews .Where(b => b.Id == reviewId && b.Approved == false && !b.Deleted) .Include(b => b.Critic).ToList()); } }