Beispiel #1
0
        public bool DeleteCritic(int criticId)
        {
            try
            {
                using (IMDBEntities7 dbContext = new IMDBEntities7())
                {
                    var critic = dbContext.Critics.Where(b => b.Id == criticId && b.Deleted == false).FirstOrDefault();

                    //brisemo kriticara za taj film
                    if (critic != null)
                    {
                        critic.Deleted = true;
                        dbContext.Entry(critic).State = EntityState.Modified;
                        dbContext.SaveChanges();

                        var       reviews   = dbContext.Reviews.Where(c => c.Critic_Id == criticId && c.Deleted == false).ToList();
                        DALReview dALReview = new DALReview();
                        reviews.ForEach(c =>
                        {
                            dALReview.DeleteReview(c.Id);
                        });

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        public bool DeleteMovie(int movieId)
        {
            try
            {
                using (IMDBEntities7 dbContext = new IMDBEntities7(true))
                {
                    var movie = dbContext.Movies.Where(b => b.Id == movieId && b.Deleted == false).FirstOrDefault();
                    if (movie != null)
                    {
                        movie.Deleted = true;
                        dbContext.Entry(movie).State = EntityState.Modified;
                        dbContext.SaveChanges();
                        //kad brisem film, brisem i njegov Id iz tabele Acts
                        List <Actor>    acts           = new List <Actor>();
                        List <Genre>    belongsToGenre = new List <Genre>();
                        List <Festival> movieFestivals = new List <Festival>();

                        foreach (var act in dbContext.Actors)
                        {
                            act.Movies.ToList().ForEach(a =>
                            {
                                if (a.Id == movieId)
                                {
                                    acts.Add(act);
                                }
                            });
                        }
                        acts.ForEach(a =>
                        {
                            a.Movies.Remove(movie);
                        });
                        dbContext.SaveChanges();
                        //brisemo iz zanrova koji su povezani sa njim
                        foreach (var genre in dbContext.Genres)
                        {
                            genre.Movies.ToList().ForEach(a =>
                            {
                                if (a.Id == movieId)
                                {
                                    belongsToGenre.Add(genre);
                                }
                            });
                        }
                        belongsToGenre.ForEach(a =>
                        {
                            a.Movies.Remove(movie);
                        });
                        dbContext.SaveChanges();

                        //brisemo ga ako je ucestvovao na festivalu iz tabele MovieFestival
                        foreach (var festival in dbContext.Festivals)
                        {
                            festival.Movies.ToList().ForEach(a =>
                            {
                                if (a.Id == movieId)
                                {
                                    movieFestivals.Add(festival);
                                }
                            });
                        }
                        movieFestivals.ForEach(a =>
                        {
                            a.Movies.Remove(movie);
                        });
                        dbContext.SaveChanges();

                        //brisemo ga iz tabele MovieFestivalAward ako je dobio neku nagradu
                        var awarded = dbContext.MovieFestivalAwards.Where(s => s.MovieFestival_Movie_Id == movieId && s.Deleted == false).ToList();
                        awarded.ForEach(s =>
                        {
                            s.Deleted = true;
                            dbContext.Entry(s).State = EntityState.Modified;
                            dbContext.SaveChanges();
                        });

                        DALReview dALReview = new DALReview();
                        //brisemo kritike za taj film
                        var reviews = dbContext.Reviews.Where(c => c.Movie_Id == movieId && c.Deleted == false).ToList();
                        reviews.ForEach(c =>
                        {
                            dALReview.DeleteReview(c.Id);
                        });

                        //brisemo i gdje se prikazuje
                        var shows = dbContext.ShowsMovies.Where(s => s.Movie_Id == movieId && s.Deleted == false).ToList();
                        shows.ForEach(s =>
                        {
                            s.Deleted = true;
                            dbContext.Entry(s).State = EntityState.Modified;
                            dbContext.SaveChanges();
                        });

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                System.Diagnostics.Debug.WriteLine("Sql Exception:" + ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message);
                return(false);
            }
        }