public ActionResult Edit(Movie movieToEdit)
        {
            try
            {
                var originalMovie = (from m in _db.Movies1

                                     where m.Id == movieToEdit.Id

                                     select m).First();

                if (!ModelState.IsValid)
                {
                    return(View(originalMovie));
                }


                _db.Movies1.Attach(movieToEdit);
                _db.Entry(movieToEdit).State = System.Data.Entity.EntityState.Modified;

                _db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> EditMovie(int id, MovieDTO movieDTO)
        {
            if (id != movieDTO.Id)
            {
                return(BadRequest());
            }
            Movie movie = await _context.Movies.FindAsync(id);

            IList <MoviePerson>   actors    = _context.MoviePersons.Where(x => x.MovieId == id).ToList();
            IList <MovieProducer> producers = _context.MovieProducers.Where(x => x.MovieId == id).ToList();

            _context.MoviePersons.RemoveRange(actors);
            _context.MovieProducers.RemoveRange(producers);

            Person director = await _context.People.FindAsync(movieDTO.DirectorId);

            Country country = await _context.Countries.FindAsync(movieDTO.CountryId);

            movie.Title    = movieDTO.Title;
            movie.Director = director;
            movie.Genre    = movieDTO.Genre;
            movie.Length   = movieDTO.Length;
            movie.Year     = movieDTO.Year;
            movie.Country  = country;
            await AddActorsToMovie(movieDTO, movie);
            await AddProducersToMovie(movieDTO, movie);

            _context.Entry(movie).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #3
0
        public IHttpActionResult PutMovy(int id, Movy movy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movy.MovieID)
            {
                return(BadRequest());
            }

            db.Entry(movy).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "MovieID,Title,Director,Genre")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movie));
 }
 public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,Phone")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Beispiel #6
0
        public bool AddUpdateMovie(MovieModel model)
        {
            try
            {
                tblMovy _movieModel = model.MovieID > 0 ? _MoviesDBEntitiesContext.tblMovies.FirstOrDefault(f => f.MovieID == model.MovieID) : new tblMovy();
                _movieModel.Name = model.Name;
                _movieModel.Plot = model.Plot;

                if (!string.IsNullOrEmpty(model.Poster))
                {
                    _movieModel.Poster            = Base64Image.Parse(model.Poster).FileContents;
                    _movieModel.PosterContentType = model.ContentType;
                }

                _movieModel.ProducerID    = model.ProducerID;
                _movieModel.YearOfRelease = model.YearOfRelease;
                _MoviesDBEntitiesContext.Entry(_movieModel).State = model.MovieID > 0 ? System.Data.Entity.EntityState.Modified : System.Data.Entity.EntityState.Added;
                _MoviesDBEntitiesContext.SaveChanges();
                if (model.MovieID > 0)
                {
                    _MoviesDBEntitiesContext.tblMovieActors.RemoveRange(_MoviesDBEntitiesContext.tblMovieActors.Where(w => w.MovieID == model.MovieID));
                    _MoviesDBEntitiesContext.SaveChanges();
                }
                foreach (int actorID in model.Actors)
                {
                    if (!_MoviesDBEntitiesContext.tblMovieActors.Any(fk => fk.ActorID == actorID && fk.MovieID == _movieModel.MovieID))
                    {
                        tblMovieActor _movieActor = new tblMovieActor();
                        _movieActor.ActorID = actorID;
                        _movieActor.MovieID = _movieModel.MovieID;
                        _MoviesDBEntitiesContext.tblMovieActors.Add(_movieActor);
                        _MoviesDBEntitiesContext.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #7
0
 public ActionResult Edit([Bind(Include = "RentalID,CustomerID,MovieID,Date")] Rental rental)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rental).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", rental.CustomerID);
     ViewBag.MovieID    = new SelectList(db.Movies, "MovieID", "Title", rental.MovieID);
     return(View(rental));
 }
Beispiel #8
0
 public ActionResult Edit(MovieViewModel movieToEdit)
 {
     if (ModelState.IsValid)
     {
         var   mapper        = new MapperConfiguration(cfg => cfg.CreateMap <MovieViewModel, Movie>()).CreateMapper();
         Movie movieSaveInDB = mapper.Map <MovieViewModel, Movie>(movieToEdit);
         entities.Entry(movieSaveInDB).State = EntityState.Modified;
         entities.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movieToEdit));
 }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,phone")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", customer.CustomerID);
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", customer.CustomerID);
     return(View(customer));
 }
        public ActionResult Edit(Movies moviesToEdit)
        {
            var originalMovie = (from m in _db.Movies1
                                 where m.Id == moviesToEdit.Id
                                 select m).First();

            if (!ModelState.IsValid)
            {
                return(View(originalMovie));
            }
            _db.Entry(originalMovie).CurrentValues.SetValues(moviesToEdit);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(Movie movieToEdit)

        {
            var originalMovie = (from m in _db.MovieSet

                                 where m.Id == movieToEdit.Id

                                 select m).First();

            if (!ModelState.IsValid)
            {
                return(View(originalMovie));
            }
            _db.Entry(originalMovie).CurrentValues.SetValues(movieToEdit);
            //_db.ApplyPropertyChanges(originalMovie.EntityKey.EntitySetName, movieToEdit);

            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> EditProducer(int id, ProducerDTO producerDTO)
        {
            if (id != producerDTO.Id)
            {
                return(BadRequest());
            }
            Producer producer = await _context.Producers.FindAsync(id);

            Country country = await _context.Countries.FindAsync(producerDTO.CountryId);

            producer.CompanyName           = producerDTO.CompanyName;
            producer.YearEstablished       = producerDTO.YearEstablished;
            producer.EstimatedCompanyValue = producerDTO.EstimatedCompanyValue;
            producer.Country = country;

            _context.Entry(producer).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }