コード例 #1
0
        public ActionResult EditMovie(MovieModel objMovie, HttpPostedFileBase Image)
        {
            IMDB_Context  context     = new IMDB_Context();
            Producers     objProducer = context.Producers.Where(x => x.ProducerId == objMovie.ProducerId).SingleOrDefault <Producers>();
            List <Actors> _ActorsList = new List <Actors>();

            foreach (var item in objMovie.ActorsId)
            {
                _ActorsList.Add(context.Actors.Where(x => x.ActorId == item).SingleOrDefault());
            }
            Movies movie = new Movies()
            {
                Name          = objMovie.Name,
                Plot          = objMovie.Plot,
                Yearofrelease = Convert.ToDateTime(objMovie.Yearofrelease),
                Poster        = objMovie.Poster,
                Producer      = objProducer,
                Actors        = _ActorsList
            };
            var mov = context.Movies.Where(x => x.MovieId == objMovie.MovieId).SingleOrDefault();

            context.Movies.Remove(mov);
            context.SaveChanges();
            mov.Name                 = movie.Name;
            mov.Plot                 = movie.Plot;
            mov.ProducerId           = objProducer.ProducerId;
            mov.Actors               = _ActorsList;
            mov.Yearofrelease        = movie.Yearofrelease;
            context.Entry(mov).State = EntityState.Added;

            context.Movies.Add(mov);
            context.SaveChanges();
            return(RedirectToAction("GetMovies", "Imdb", null));
        }
コード例 #2
0
        public ActionResult AddMovie(MovieModel objMovie, HttpPostedFileBase Image)
        {
            //Byte[] imagearray =
            IMDB_Context context = new IMDB_Context();

            if (Image != null && Image.ContentLength > 0)
            {
                var fileName = Path.GetFileName(Image.FileName);
                var path     = Path.Combine(Server.MapPath("~/App_Data/Images"), fileName);
                Image.SaveAs(path);

                objMovie.Poster = new byte[Image.ContentLength];
                Image.InputStream.Read(objMovie.Poster, 0, Image.ContentLength);
            }

            Producers     objProducer = context.Producers.Where(x => x.ProducerId == objMovie.ProducerId).SingleOrDefault <Producers>();
            List <Actors> _ActorsList = new List <Actors>();

            foreach (var item in objMovie.ActorsId)
            {
                _ActorsList.Add(context.Actors.Where(x => x.ActorId == item).SingleOrDefault());
            }
            Movies movie = new Movies()
            {
                Name          = objMovie.Name,
                Plot          = objMovie.Plot,
                Yearofrelease = Convert.ToDateTime(objMovie.Yearofrelease),
                Poster        = objMovie.Poster,
                Producer      = objProducer,
                Actors        = _ActorsList
            };

            context.Movies.Add(movie);
            context.Entry(movie).State = System.Data.Entity.EntityState.Added;
            context.SaveChanges();
            return(RedirectToAction("GetMovies", "Imdb", null));
        }