Exemple #1
0
        public void ModifyMovie(Movies movie, List <int> actorids, HttpPostedFileBase File)
        {
            // String path = ConfigurationManager.AppSettings["Path"];
            String path   = "C:\\users\\rajat\\source\\repos\\IMBD\\IMBD\\Content\\Posters\\";
            Movies modify = _context.Movies.First(m => m.Name == movie.Name);
            List <Actor_Movies> actorMovies = _context.Actor_Movies.ToList();

            modify.Name        = movie.Name;
            modify.Plot        = movie.Plot;
            modify.ReleaseDate = movie.ReleaseDate;
            modify.ProducerId  = movie.ProducerId;
            _context.SaveChanges();
            if (File != null)
            {
                File.SaveAs(Path.Combine(@path, "" + modify.Id + ".jpg"));
            }
            bool present = false;

            List <int> existingIds = new List <int>();

            existingIds = actorMovies.Where(s => s.MovieId == modify.Id).Select(s => s.ActorId).ToList();
            //existingIds = (from am in actormovies where am.MovieId == modify.Id select am.ActorId).ToList();
            foreach (int id in actorids)
            {
                if ((actorMovies.Where(s => s.ActorId == id && s.MovieId == modify.Id).Count() == 0))
                {
                    var actor_movie = new Actor_Movies()
                    {
                        MovieId = modify.Id,
                        ActorId = id
                    };
                    _context.Actor_Movies.Add(actor_movie);
                    _context.SaveChanges();
                }
            }
            foreach (int eid in existingIds)
            {
                present = false;
                foreach (int id in actorids)
                {
                    if (eid == id)
                    {
                        present = true;
                        break;
                    }
                }
                if (!present)
                {
                    Actor_Movies actor_Movie = actorMovies.Where(a => a.MovieId == modify.Id && a.ActorId == eid).Single();
                    // Actor_Movies actor_movie = (from am in actormovies where am.MovieId == modify.Id where am.ActorId == eid select am).First();

                    _context.Actor_Movies.Remove(actor_Movie);
                    _context.SaveChanges();
                }
            }
        }
Exemple #2
0
        public ActionResult Create(AddMovieViewModel viewmodel)
        {
            try
            {
                String s    = viewmodel.Name;
                String path = "C:\\users\\rajat\\source\\repos\\IMBD\\IMBD\\Content\\Posters\\";
                //String path = ConfigurationManager.AppSettings["Path"];
                //   viewmodel.File.SaveAs(path+viewmodel.Id);


                Image source = Image.FromStream(viewmodel.File.InputStream);

                var NewMovie = new Movies()
                {
                    Name        = viewmodel.Name,
                    ReleaseDate = viewmodel.ReleaseDate,
                    Plot        = viewmodel.Plot,
                    PosterId    = 123,
                    ProducerId  = viewmodel.producer
                };
                moviesRepository.AddMovie(NewMovie);


                viewmodel.File.SaveAs(Path.Combine(@path, "" + NewMovie.Id + ".jpg"));

                foreach (int i in viewmodel.ActorIds)
                {
                    var actor_mov = new Actor_Movies()
                    {
                        MovieId = NewMovie.Id,
                        ActorId = i
                    };
                    actor_MoviesRepository.Add(actor_mov);
                }

                return(RedirectToAction("Add"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #3
0
 public void Add(Actor_Movies actor_movie)
 {
     context.Actor_Movies.Add(actor_movie);
     context.SaveChanges();
 }